diff --git a/releasenotes/notes/tripleo-docker-rm-b64297d5f9f42988.yaml b/releasenotes/notes/tripleo-docker-rm-b64297d5f9f42988.yaml new file mode 100644 index 000000000..fc39e9487 --- /dev/null +++ b/releasenotes/notes/tripleo-docker-rm-b64297d5f9f42988.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + The new tripleo-docker-rm will be useful to remove the containers that + were managed by Docker and that are now managed by Podman. diff --git a/roles/tripleo-docker-rm/README.md b/roles/tripleo-docker-rm/README.md new file mode 100644 index 000000000..1f9a2a5c1 --- /dev/null +++ b/roles/tripleo-docker-rm/README.md @@ -0,0 +1,40 @@ +tripleo-docker-rm +================= + +An Ansible role to remove Docker containers when Podman is enabled. + +Requirements +------------ + +It requires python-docker on the host. + +Role variables +-------------- + +- container_cli: -- Name of the Container CLI tool (default to docker). +- containers_to_rm: -- List of containers to remove. + +Example Playbook +---------------- + +Sample playbook to call the role: + + - name: Remove Nova API docker containers + hosts: all + roles: + - tripleo-docker-rm + vars: + containers_to_rm: + - nova_api + - nova_api_cron + container_cli: podman + +License +------- + +Free software: Apache License (2.0) + +Author Information +------------------ + +OpenStack TripleO team diff --git a/roles/tripleo-docker-rm/defaults/main.yaml b/roles/tripleo-docker-rm/defaults/main.yaml new file mode 100644 index 000000000..211d13ff7 --- /dev/null +++ b/roles/tripleo-docker-rm/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +container_cli: docker diff --git a/roles/tripleo-docker-rm/tasks/main.yaml b/roles/tripleo-docker-rm/tasks/main.yaml new file mode 100644 index 000000000..76cb49922 --- /dev/null +++ b/roles/tripleo-docker-rm/tasks/main.yaml @@ -0,0 +1,17 @@ +--- +- name: Check if docker is installed + stat: + path: /usr/bin/docker + register: docker_path_stat + +- set_fact: + docker_installed: "{{ docker_path_stat.results | map(attribute='stat') | map(attribute='exists') is any }}" + +- name: remove "{{ containers_to_rm|join(', ') }}" containers + docker_container: + name: "{{ item }}" + state: absent + when: + - container_cli == 'podman' + - docker_installed + with_items: "{{ containers_to_rm }}"