Skip to content

Commit

Permalink
parameterize health check; refactor serial_then_parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
guidograzioli committed May 16, 2024
1 parent f63b20b commit 4b21569
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 28 deletions.
2 changes: 2 additions & 0 deletions roles/keycloak_quarkus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ Role Defaults
|`keycloak_quarkus_systemd_wait_for_delay`| Activation delay for service systemd unit (seconds) | `10` |
|`keycloak_quarkus_restart_strategy`| Strategy task file for restarting in HA (one of provided restart/['serial.yml','none.yml','serial_then_parallel.yml']) or path to file when providing custom strategy | `restart/serial.yml` |
|`keycloak_quarkus_restart_health_check`| Whether to wait for successful health check after restart | `{{ keycloak_quarkus_ha_enabled }}` |
|`keycloak_quarkus_restart_health_check_delay`| Seconds to let pass before starting healch checks | `10` |
|`keycloak_quarkus_restart_health_check_reries`| Number of attempts for successful health check before failing | `25` |
|`keycloak_quarkus_restart_pause`| Seconds to wait between restarts in HA strategy | `15` |


Expand Down
2 changes: 2 additions & 0 deletions roles/keycloak_quarkus/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,6 @@ keycloak_quarkus_supported_policy_types: ['password-blacklists']
# files in restart directory (one of [ 'serial', 'none', 'serial_then_parallel' ]), or path to file when providing custom strategy
keycloak_quarkus_restart_strategy: restart/serial.yml
keycloak_quarkus_restart_health_check: "{{ keycloak_quarkus_ha_enabled }}"
keycloak_quarkus_restart_health_check_delay: 10
keycloak_quarkus_restart_health_check_reries: 25
keycloak_quarkus_restart_pause: 15
8 changes: 8 additions & 0 deletions roles/keycloak_quarkus/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,14 @@ argument_specs:
description: "Seconds to wait between restarts in HA strategy"
default: 15
type: int
keycloak_quarkus_restart_health_check_delay:
description: "Seconds to let pass before starting healch checks"
default: 10
type: 'int'
keycloak_quarkus_restart_health_check_reries:
description: "Number of attempts for successful health check before failing"
default: 25
type: 'int'
downstream:
options:
rhbk_version:
Expand Down
6 changes: 3 additions & 3 deletions roles/keycloak_quarkus/tasks/restart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
url: "{{ keycloak.health_url }}"
register: keycloak_status
until: keycloak_status.status == 200
retries: 25
delay: 10
when: keycloak_quarkus_restart_health_check
retries: "{{ keycloak_quarkus_restart_health_check_reries }}"
delay: "{{ keycloak_quarkus_restart_health_check_delay }}"
when: internal_force_health_check | default(keycloak_quarkus_restart_health_check)

- name: Pause to give distributed ispn caches time to (re-)replicate back onto first host
ansible.builtin.pause:
Expand Down
33 changes: 8 additions & 25 deletions roles/keycloak_quarkus/tasks/restart/serial_then_parallel.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,14 @@
---
- name: Verify first restarted service with health URL, then rest restart in parallel
block:
- name: "Restart and enable {{ keycloak.service_name }} service on first host"
ansible.builtin.systemd:
name: "{{ keycloak.service_name }}"
enabled: true
state: restarted
daemon_reload: true
become: true
delegate_to: "{{ ansible_play_hosts | first }}"
run_once: true

- name: "Wait until {{ keycloak.service_name }} service becomes active {{ keycloak.health_url }}"
ansible.builtin.uri:
url: "{{ keycloak.health_url }}"
register: keycloak_status
until: keycloak_status.status == 200
retries: 25
delay: 10
delegate_to: "{{ ansible_play_hosts | first }}"
run_once: true

- name: Pause to give distributed ispn caches time to (re-)replicate back onto first host
ansible.builtin.pause:
seconds: "{{ keycloak_quarkus_restart_pause }}"
when:
- keycloak_quarkus_ha_enabled
- name: "Restart and enable {{ keycloak.service_name }} service on initial host"
ansible.builtin.include_tasks:
file: restart.yml
apply:
delegate_to: "{{ ansible_play_hosts | first }}"
run_once: true
vars:
internal_force_health_check: true

- name: "Restart and enable {{ keycloak.service_name }} service on other hosts"
ansible.builtin.systemd:
Expand Down

0 comments on commit 4b21569

Please sign in to comment.