Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openstackclient: improve service start #1246

Merged
merged 1 commit into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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