Introduce tripleo-container-rm

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.

Change-Id: I3fc5b351c3e20ab01953a510bd71a70d3c083527
This commit is contained in:
Emilien Macchi 2019-05-05 17:24:27 +01:00
parent 508324b1f4
commit 13775b8e20
7 changed files with 112 additions and 0 deletions

View File

@ -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.

View File

@ -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

View File

@ -0,0 +1,2 @@
---
container_cli: podman

View File

@ -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 }}"

View File

@ -0,0 +1,5 @@
---
- include_tasks: "{{ container_cli }}.yaml"
vars:
container: "{{ item }}"
with_items: "{{ containers_to_rm }}"

View File

@ -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

View File

@ -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
------------