docker-rm: check if rpm dependency is actually installed

If the deployment wasn't deployed under Docker, python2-docker package
is missing. Therefore, during the upgrade we don't want to try to remove
the containers under Docker, since they don't exist anyway.

python2-docker is needed by Ansible to remove the containers, so let's
make sure the package is installed, which is the case when the
deployment was under Docker.
If the rpm doesn't exist, we'll skip the tasks and don't try to remove
the containers.

The main case where docker-rm is useful is when upgrading on centos7
from rocky to stein, since we clear containers running in Docker during
the upgrade, so they run on Podman.

In reality, the future platform won't have Docker installed, so this
role will become useless and we'll probably deprecate it.

Closes-Bug: #1824301
Change-Id: Ic5036ffa756775e3806e18b09e034af2290bfb56
(cherry picked from commit e368e15226)
This commit is contained in:
Emilien Macchi 2019-04-11 09:57:00 -04:00
parent 992749c69f
commit f19863f332
1 changed files with 7 additions and 6 deletions

View File

@ -1,11 +1,12 @@
---
- name: Check if docker is installed
stat:
path: /usr/bin/docker
register: docker_path_stat
- name: Check if python2-docker is installed
command: /usr/bin/rpm -q python2-docker
register: py2_docker_installed
ignore_errors: true
changed_when: false
- name: Ensure docker service is running
when: docker_path_stat.stat.exists
when: py2_docker_installed.rc|default('') == 0
systemd:
name: docker
register: docker_service_state
@ -16,6 +17,6 @@
state: absent
when:
- container_cli == 'podman'
- docker_path_stat.stat.exists
- py2_docker_installed.rc|default('') == 0
- docker_service_state.status['SubState'] == 'running'
with_items: "{{ containers_to_rm }}"