forked from wzzrd/automates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_loadbalancer.yml
54 lines (47 loc) · 1.7 KB
/
create_loadbalancer.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
---
- name: create loadbalancer setup
hosts: all
remote_user: ansible
become: yes
vars:
haproxy_backend_name: 'habackend'
haproxy_backend_mode: 'http'
haproxy_backend_balance_method: 'roundrobin'
haproxy_backend_httpchk: 'HEAD / HTTP/1.1\r\nHost:localhost'
haproxy_frontend_name: 'hafrontend'
haproxy_frontend_bind_address: '*'
haproxy_frontend_port: 80
haproxy_frontend_mode: 'http'
haproxy_stats_enable: true
haproxy_stats_port: 8080
haproxy_stats_refresh: 15s
haproxy_stats_username: 'admin'
haproxy_stats_password: 'okboomer'
haproxy_stats_uri: /stats
pre_tasks:
- name: create webserver and loadbalancer group
group_by:
key: server_role_{{ ansible_local['facts']['server_role'] }}
- name: create empty list for collection of backend servers
set_fact:
backend_server_list: []
- name: populate loadbalancer list of dictionaries
set_fact:
backend_server_list: "{{ backend_server_list + [ {'name': item, 'address': hostvars[item]['ansible_local']['facts']['external_ip'] + ':80'}] }}"
loop: "{{ query('inventory_hostnames', 'server_role_webserver:!server_role_loadbalancer') }}"
tasks:
- include_role:
name: geerlingguy.haproxy
vars:
haproxy_backend_servers: "{{ backend_server_list }}"
when: "ansible_fqdn == 'loadbalancer.ibm.nontoonyt.com'"
post_tasks:
- name: add cloud servers to pool
haproxy:
state: enabled
host: " {{ ansible_host }}"
socket: /var/lib/haproxy/stats
weight: 10
backend: habackend
delegate_to: loadbalancer.ibm.nontoonyt.com
when: "ansible_fqdn != 'loadbalancer.ibm.nontoonyt.com'"