Skip to content

Commit

Permalink
openstackclient: improve service start (#1246)
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Berendt <[email protected]>
  • Loading branch information
berendt authored Dec 30, 2023
1 parent 9fd88f8 commit 4607a0d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 24 deletions.
36 changes: 36 additions & 0 deletions roles/openstackclient/handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 0 additions & 24 deletions roles/openstackclient/tasks/container-Debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4607a0d

Please sign in to comment.