File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 >"
Original file line number Diff line number Diff line change 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) }}"
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) }] }}"
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
You can’t perform that action at this time.
0 commit comments