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:
parent
508324b1f4
commit
13775b8e20
@ -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.
|
34
roles/tripleo-container-rm/README.md
Normal file
34
roles/tripleo-container-rm/README.md
Normal 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
|
2
roles/tripleo-container-rm/defaults/main.yaml
Normal file
2
roles/tripleo-container-rm/defaults/main.yaml
Normal file
@ -0,0 +1,2 @@
|
||||
---
|
||||
container_cli: podman
|
21
roles/tripleo-container-rm/tasks/docker.yaml
Normal file
21
roles/tripleo-container-rm/tasks/docker.yaml
Normal 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 }}"
|
5
roles/tripleo-container-rm/tasks/main.yaml
Normal file
5
roles/tripleo-container-rm/tasks/main.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
- include_tasks: "{{ container_cli }}.yaml"
|
||||
vars:
|
||||
container: "{{ item }}"
|
||||
with_items: "{{ containers_to_rm }}"
|
41
roles/tripleo-container-rm/tasks/podman.yaml
Normal file
41
roles/tripleo-container-rm/tasks/podman.yaml
Normal 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
|
@ -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
|
||||
------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user