Add playbook to stop containers (stein only)

We need to stop several containers on the upgrades workflow.

This submission allows to reduce the duplicated code in THT.
It also handles the case in which we have podman as the CLI
but the containers running with docker.

The submission is proposed for tripleo-common only for
stable/stein, the master patch needs to be moved to the
tripleo-ansible repository as all the Ansible automation
is moved to that new repository.

Change-Id: I3c0580893aed5bda46d9104ffcee0f00cbabd9ee
This commit is contained in:
Carlos Camacho 2019-07-03 17:25:54 +02:00
parent b6a2d65246
commit 14244253ea
4 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,35 @@
tripleo-container-stop
======================
An Ansible role to stop containers.
Role variables
--------------
- tripleo_containers_to_stop: -- Containers names to stop.
- tripleo_delegate_to: -- Delegate the execution of this role.
Example Playbook
----------------
Sample playbook to call the role:
- name: Stop a set of container
hosts: all
roles:
- tripleo-container-stop
vars:
tripleo_containers_to_stop:
- nova_api
- nova_api_cron
tripleo_delegate_to: localhost
License
-------
Free software: Apache License (2.0)
Author Information
------------------
OpenStack TripleO team

View File

@ -0,0 +1,3 @@
---
tripleo_containers_to_stop: "{{ default([]) }}"
tripleo_delegate_to: ["localhost"]

View File

@ -0,0 +1,19 @@
---
- name: Make sure the container is stopped even if container_cli do not match
become: true
shell: |
# We need to make sure that containers are stopped
# as we might have different CLIs to interact with
# them. I.e the container_cli might be setted to be podman
# but we might have the containers running with docker.
set -eu
if command -v podman && podman exec {{ container }} /bin/true; then
systemctl stop tripleo_{{ container }}.service
fi
if type docker &> /dev/null && docker exec {{ container }} /bin/true; then
docker stop {{ container }}
fi
delegate_to: "{{ tripleo_delegate_to_item }}"
with_items: "{{ tripleo_delegate_to }}"
loop_control:
loop_var: tripleo_delegate_to_item

View File

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