-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #451 from OpenConext/feature/refactor_haproxy_mgnt
Haproxy management role:
- Loading branch information
Showing
2 changed files
with
48 additions
and
139 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,59 @@ | ||
--- | ||
- name: Check if the patchproces is running, except when called from the patchproces | ||
stat: | ||
path: /tmp/patchprocesstarted | ||
register: patch_process_started | ||
- name: Extract list of application names | ||
ansible.builtin.set_fact: | ||
app_names: "{{ haproxy_applications | map(attribute='name') | list }}" | ||
|
||
- block: | ||
- name: End the play if the patchprocess is running | ||
debug: | ||
msg: "The patchprocess is running. No loadbalancer management allowed" | ||
- meta: end_play | ||
when: patch_process_started.stat.exists and skip_patch_check is not defined | ||
- name: Check if dynamic_input exists in haproxy_applications | ||
ansible.builtin.set_fact: | ||
app_exists: "{{ app_name in app_names }}" | ||
|
||
- name: get new weight for haproxy hosts | ||
haproxy_commands: | ||
java_blauwrood_servers: "{{ java_blauwrood_servers }}" | ||
php_blauwrood_servers: "{{ php_blauwrood_servers }}" | ||
static_blauwrood_servers: "{{ static_blauwrood_servers }}" | ||
stepup_blauwrood_servers: "{{ stepup_blauwrood_servers }}" | ||
docker_blauwrood_servers: "{{ docker_blauwrood_servers }}" | ||
weight: "{{ weight }}" | ||
color: "{{ color }}" | ||
app_name: "{{ app_name }}" | ||
app_type: "{{ app_type }}" | ||
when: weight is defined | ||
register: haproxy_weights | ||
- name: Fail if dynamic_input does not exist in haproxy_applications | ||
ansible.builtin.fail: | ||
msg: "The application '{{ app_name }}' does not exist in haproxy_applications. Available applications are: {{ app_names | join(', ') }}" | ||
when: not app_exists | ||
|
||
- name: get new state for haproxy hosts | ||
haproxy_commands: | ||
java_blauwrood_servers: "{{ java_blauwrood_servers }}" | ||
php_blauwrood_servers: "{{ php_blauwrood_servers }}" | ||
static_blauwrood_servers: "{{ static_blauwrood_servers }}" | ||
stepup_blauwrood_servers: "{{ stepup_blauwrood_servers }}" | ||
docker_blauwrood_servers: "{{ docker_blauwrood_servers }}" | ||
color: "{{ color }}" | ||
state: "{{ state }}" | ||
app_name: "{{ app_name }}" | ||
app_type: "{{ app_type }}" | ||
when: state is defined | ||
register: haproxy_states | ||
- name: Set the complementing weight | ||
ansible.builtin.set_fact: | ||
weight_complementing: "{{ 100 - weight | int }}" | ||
|
||
- name: dump weight output | ||
debug: | ||
msg: '{{ haproxy_weights.haproxy_items }}' | ||
when: weight is defined | ||
- name: Get the server list from the servers configured in haproxy_applications | ||
ansible.builtin.set_fact: | ||
selected_servers: "{{ (haproxy_applications | selectattr('name', 'equalto', app_name) | map(attribute='servers') | first) }}" | ||
|
||
- name: dump state output | ||
debug: | ||
msg: '{{ haproxy_states.haproxy_items }}' | ||
when: state is defined | ||
- name: Check if the patchproces is running, except when called from the patchproces | ||
ansible.builtin.stat: | ||
path: /tmp/patchprocesstarted | ||
register: patch_process_started | ||
|
||
- name: set weights for haproxy hosts | ||
haproxy: | ||
- block: | ||
- name: End the play if the patchprocess is running | ||
ansible.builtin.debug: | ||
msg: "The patchprocess is running. No loadbalancer management allowed" | ||
- ansible.builtin.meta: end_play | ||
when: patch_process_started.stat.exists and skip_patch_check is not defined | ||
|
||
- name: Create an empty list | ||
ansible.builtin.set_fact: | ||
server_labels_with_weights: [] | ||
|
||
- name: Create list with labels and weights as dictionaries | ||
ansible.builtin.set_fact: | ||
server_labels_with_weights: "{{ server_labels_with_weights + [{ 'label': item.label, 'weight': (weight if item[app_filter] == app_filtervalue else weight_complementing) }] }}" | ||
loop: "{{ selected_servers }}" | ||
|
||
- name: Show the created list | ||
ansible.builtin.debug: | ||
msg: "{{ server_labels_with_weights }}" | ||
|
||
- name: Set weights for haproxy hosts | ||
community.general.haproxy: | ||
state: enabled | ||
host: "{{ item.host }}" | ||
fail_on_not_found: yes | ||
socket: /var/lib/haproxy/haproxy.stats | ||
weight: "{{ item.weight }}" | ||
backend: "{{ item.backend }}" | ||
with_items: "{{ haproxy_weights.haproxy_items }}" | ||
when: weight is defined | ||
|
||
- name: set state for haproxy hosts | ||
haproxy: | ||
state: "{{ item.state }}" | ||
host: "{{ item.host }}" | ||
fail_on_not_found: yes | ||
host: "{{ item.label }}" | ||
fail_on_not_found: true | ||
socket: /var/lib/haproxy/haproxy.stats | ||
backend: "{{ item.backend }}" | ||
with_items: "{{ haproxy_states.haproxy_items }}" | ||
when: state is defined | ||
weight: "{{ item.weight }}%" | ||
backend: "{{ app_name }}_be" | ||
with_items: "{{ server_labels_with_weights }}" | ||
|
||
- name: Write the state to the correct state file | ||
shell: echo "show servers state" | socat /var/lib/haproxy/haproxy.stats - > /var/lib/haproxy/state | ||
ansible.builtin.shell: echo "show servers state" | socat /var/lib/haproxy/haproxy.stats - > /var/lib/haproxy/state |