diff --git a/roles/tripleo-container-stop/README.md b/roles/tripleo-container-stop/README.md new file mode 100644 index 000000000..f2a747b02 --- /dev/null +++ b/roles/tripleo-container-stop/README.md @@ -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 diff --git a/roles/tripleo-container-stop/defaults/main.yaml b/roles/tripleo-container-stop/defaults/main.yaml new file mode 100644 index 000000000..00b367162 --- /dev/null +++ b/roles/tripleo-container-stop/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +tripleo_containers_to_stop: "{{ default([]) }}" +tripleo_delegate_to: ["localhost"] diff --git a/roles/tripleo-container-stop/tasks/container_stop.yaml b/roles/tripleo-container-stop/tasks/container_stop.yaml new file mode 100644 index 000000000..1c814e12a --- /dev/null +++ b/roles/tripleo-container-stop/tasks/container_stop.yaml @@ -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 diff --git a/roles/tripleo-container-stop/tasks/main.yaml b/roles/tripleo-container-stop/tasks/main.yaml new file mode 100644 index 000000000..055a07efc --- /dev/null +++ b/roles/tripleo-container-stop/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- include_tasks: "container_stop.yaml" + vars: + container: "{{ item }}" + with_items: "{{ tripleo_containers_to_stop }}"