diff --git a/roles/openstackclient/handlers/main.yml b/roles/openstackclient/handlers/main.yml index 80c038658..3f9662494 100644 --- a/roles/openstackclient/handlers/main.yml +++ b/roles/openstackclient/handlers/main.yml @@ -4,3 +4,39 @@ ansible.builtin.service: name: "{{ openstackclient_service_name }}" state: restarted + notify: + - Ensure that all containers are up + +- name: Ensure that all containers are up + ansible.builtin.command: + cmd: docker compose --project-directory /opt/openstackclient up -d + changed_when: true + notify: + - Wait for an healthy service + +# NOTE: The command returns a list of IDs of containers from the service +# that are currently starting or unhealthy. As long as the list is not empty +# the service is not in a good state. +- name: Wait for an healthy service + ansible.builtin.shell: | + set -o pipefail + docker compose --project-directory /opt/openstackclient \ + ps --all --format json | \ + jq '. | select(.State=="created" or .State=="exited" or .Health=="starting" or .Health=="unhealthy") | .Name' + args: + executable: /bin/bash + register: result + until: "result.stdout | length == 0" + retries: 20 + delay: 10 + changed_when: true + notify: + - Copy bash completion script + +- name: Copy bash completion script + become: true + ansible.builtin.command: "docker cp {{ openstackclient_container_name }}:/osc.bash_completion /etc/bash_completion.d/openstack" + register: result + changed_when: false + failed_when: result.rc != 0 + ignore_errors: true diff --git a/roles/openstackclient/tasks/container-Debian.yml b/roles/openstackclient/tasks/container-Debian.yml index dfb02182c..7e0875905 100644 --- a/roles/openstackclient/tasks/container-Debian.yml +++ b/roles/openstackclient/tasks/container-Debian.yml @@ -43,27 +43,3 @@ ansible.builtin.file: path: /usr/local/bin/ospurge state: absent - -# NOTE: The command returns a list of IDs of containers from the service -# that are currently starting or unhealthy. As long as the list is not empty -# the service is not in a good state. -- name: Wait for an healthy service - ansible.builtin.shell: | - set -o pipefail - docker compose --project-directory /opt/openstackclient \ - ps --all --format json | \ - jq '. | select(.State=="created" or .State=="exited" or .Health=="starting" or .Health=="unhealthy") | .Name' - args: - executable: /bin/bash - register: result - until: "result.stdout | length == 0" - retries: 20 - delay: 10 - changed_when: true - -- name: Copy bash completion script - become: true - ansible.builtin.command: "docker cp {{ openstackclient_container_name }}:/osc.bash_completion /etc/bash_completion.d/openstack" - register: result - changed_when: false - failed_when: result.rc != 0