diff --git a/releasenotes/notes/tripleo-container-rm-082aa93d2de1e8bc.yaml b/releasenotes/notes/tripleo-container-rm-082aa93d2de1e8bc.yaml new file mode 100644 index 000000000..69c8c70b9 --- /dev/null +++ b/releasenotes/notes/tripleo-container-rm-082aa93d2de1e8bc.yaml @@ -0,0 +1,7 @@ +--- +features: + - | + tripleo-container-rm is the new role that replaces tripleo-docker-rm which + is in charge of tearing down containers running in Docker or Podman. + If the container_cli is Podman, the role takes care of systemd cleanup for + both the container and its healthcheck if it does exist. diff --git a/roles/tripleo-container-rm/README.md b/roles/tripleo-container-rm/README.md new file mode 100644 index 000000000..e7b5bfa15 --- /dev/null +++ b/roles/tripleo-container-rm/README.md @@ -0,0 +1,34 @@ +tripleo-container-rm +==================== + +An Ansible role to tear-down containers. + +Role variables +-------------- + +- container_cli: -- Name of the Container CLI tool (default to podman). +- 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-container-rm + vars: + containers_to_rm: + - nova_api + - nova_api_cron + +License +------- + +Free software: Apache License (2.0) + +Author Information +------------------ + +OpenStack TripleO team diff --git a/roles/tripleo-container-rm/defaults/main.yaml b/roles/tripleo-container-rm/defaults/main.yaml new file mode 100644 index 000000000..b4c003563 --- /dev/null +++ b/roles/tripleo-container-rm/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +container_cli: podman diff --git a/roles/tripleo-container-rm/tasks/docker.yaml b/roles/tripleo-container-rm/tasks/docker.yaml new file mode 100644 index 000000000..bd246b647 --- /dev/null +++ b/roles/tripleo-container-rm/tasks/docker.yaml @@ -0,0 +1,21 @@ +--- +- 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: py2_docker_installed.rc|default('') == 0 + systemd: + name: docker + register: docker_service_state + +- name: remove "{{ containers_to_rm|join(', ') }}" containers + docker_container: + name: "{{ item }}" + state: absent + when: + - py2_docker_installed.rc|default('') == 0 + - docker_service_state.status['SubState'] == 'running' + with_items: "{{ containers_to_rm }}" diff --git a/roles/tripleo-container-rm/tasks/main.yaml b/roles/tripleo-container-rm/tasks/main.yaml new file mode 100644 index 000000000..eb275303e --- /dev/null +++ b/roles/tripleo-container-rm/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- include_tasks: "{{ container_cli }}.yaml" + vars: + container: "{{ item }}" + with_items: "{{ containers_to_rm }}" diff --git a/roles/tripleo-container-rm/tasks/podman.yaml b/roles/tripleo-container-rm/tasks/podman.yaml new file mode 100644 index 000000000..9cc89f956 --- /dev/null +++ b/roles/tripleo-container-rm/tasks/podman.yaml @@ -0,0 +1,41 @@ +--- +- name: check if {{ container }} service healthcheck exists in systemd + stat: path="/etc/systemd/system/tripleo_{{ container }}_healthcheck.service" + register: systemd_healthcheck_exists +- name: tear-down {{ container }} healthcheck + when: systemd_healthcheck_exists.stat.exists + block: + - name: stop and disable {{ container }} healthcheck + systemd: + name: "tripleo_{{ container }}_healthcheck" + state: stopped + enabled: no + - name: remove {{ container }} healthcheck service + file: + path: "/etc/systemd/system/tripleo_{{ container }}_healthcheck.service" + state: absent + - name: remove {{ container }} healthcheck timer + file: + path: "/etc/systemd/system/tripleo_{{ container }}_healthcheck.timer" + state: absent +- name: check if {{ container }} service exists in systemd + stat: path="/etc/systemd/system/tripleo_{{ container }}.service" + register: systemd_exists +- name: tear-down {{ container }} container + when: systemd_exists.stat.exists + block: + - name: stop and disable {{ container }} + systemd: + name: "tripleo_{{ container }}" + state: stopped + enabled: no + - name: remove {{ container }} systemd service + file: + path: "/etc/systemd/system/tripleo_{{ container }}.service" + state: absent + - name: remove {{ container }} container + command: podman rm {{ container }} +- name: Reload systemd services if needed + when: systemd_healthcheck_exists.stat.exists or systemd_exists.stat.exists + systemd: + daemon_reload: yes diff --git a/roles/tripleo-docker-rm/README.md b/roles/tripleo-docker-rm/README.md index 1f9a2a5c1..5f268261a 100644 --- a/roles/tripleo-docker-rm/README.md +++ b/roles/tripleo-docker-rm/README.md @@ -2,6 +2,8 @@ tripleo-docker-rm ================= An Ansible role to remove Docker containers when Podman is enabled. +This role is being replaced by tripleo-container-rm which will support +podman. Requirements ------------