Skip to content

Commit d9d2151

Browse files
committed
Do some explaining
1 parent b3fdcb5 commit d9d2151

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

roles/haproxy_mgnt/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
usage for rood/blauw deployment:
2+
3+
an example playbook:
4+
5+
---
6+
- name: Change loadbalancer state
7+
hosts: loadbalancer_ha
8+
become: false
9+
gather_facts: false
10+
roles:
11+
- { role: haproxy_mgnt, tags: ['haproxy_mgnt'] }
12+
13+
in group_vars set haproxy_applications:
14+
15+
haproxy_applications:
16+
17+
- name: <APP>
18+
vhost_name: <APP>.{{ base_domain }}
19+
ha_method: "GET"
20+
ha_url: "/health"
21+
port: "{{ loadbalancing.engine.port }}"
22+
servers: "{{ docker_servers }}"
23+
24+
and set servers, add a color label:
25+
26+
docker_servers:
27+
- { ip: "<IPROOD>", label: "docker", color: "rood" }
28+
- { ip: "<IPBLAUW>", label: "docker", color: "blauw" }
29+
30+
ansible-playbook -i <INVENTORY> --tags haproxy_mgnt <PLAYBOOKNAME> -e "weight=<WEIGHT>" -e "app_name=<APP>" -e app_filter=color
31+
-e "app_filtervalue=<COLOR>"

roles/haproxy_mgnt/tasks/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
ansible.builtin.set_fact:
1717
weight_complementing: "{{ 100 - weight | int }}"
1818

19+
# get a list of servers from haproxy_applications, we filter on app_name
1920
- name: Get the server list from the servers configured in haproxy_applications
2021
ansible.builtin.set_fact:
2122
selected_servers: "{{ (haproxy_applications | selectattr('name', 'equalto', app_name) | map(attribute='servers') | first) }}"
@@ -36,6 +37,9 @@
3637
ansible.builtin.set_fact:
3738
server_labels_with_weights: []
3839

40+
# Here we set weight for app_filter = app_filtervalue (for example color=blauw) to weight
41+
# weight_complementing (100 - weight) on other servers (for example color=rood)
42+
# we get the corresponding label (for example DOCKER2ROOD ) and add this to the list of dictionaries
3943
- name: Create list with labels and weights as dictionaries
4044
ansible.builtin.set_fact:
4145
server_labels_with_weights: "{{ server_labels_with_weights + [{ 'label': item.label, 'weight': (weight if item[app_filter] == app_filtervalue else weight_complementing) }] }}"
@@ -45,6 +49,8 @@
4549
ansible.builtin.debug:
4650
msg: "{{ server_labels_with_weights }}"
4751

52+
# Now we have a label and the weight we want to set
53+
# lets write it to the socket
4854
- name: Set weights for haproxy hosts
4955
community.general.haproxy:
5056
state: enabled

0 commit comments

Comments
 (0)