Skip to content

Commit 3824356

Browse files
authored
Feature/new loadbalancer playbook (#506)
added separate loadbalancer playbook added test loadbalancer playbook
1 parent 3889e98 commit 3824356

8 files changed

Lines changed: 99 additions & 37 deletions

File tree

config_base_playbook.yml

Lines changed: 0 additions & 36 deletions
This file was deleted.

deploy_loadbalancers_playbook.yml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,28 @@
1-
---
1+
---
2+
- name: Read secrets
3+
hosts: loadbalancer
4+
become: true
5+
tasks:
6+
- name: Read vars from secrets file
7+
ansible.builtin.include_vars: "{{ inventory_dir }}/secrets/secrets.yml"
8+
no_log: true
9+
tags:
10+
- always
11+
12+
- name: Deploy haproxy
13+
hosts: loadbalancer
14+
gather_facts: true
15+
become: true
16+
roles:
17+
- role: haproxy
18+
tags: ['core', 'loadbalancer', 'lb']
19+
20+
- name: Deploy keepalived and bind for clustered loadbalancers
21+
hosts: loadbalancer_ha
22+
gather_facts: true
23+
become: true
24+
roles:
25+
- role: keepalived
26+
tags: ['core', 'loadbalancer_ha', 'keepalived']
27+
- role: bind
28+
tags: ['core', 'loadbalancer_ha', 'bind']

environments/template/group_vars/template.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
23
env: "%env%"
34
mariadb_host: localhost
45
rsyslog_host: localhost

environments/template/inventory

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@ dbcluster_nodes
5555
localhost ansible_connection=local
5656

5757
# for refactored playbooks
58+
59+
[%location%:children] # create one or more groups here for your chosen location(s)
60+
storage
61+
mongo_servers
62+
sysloghost
63+
loadbalancer_ha
64+
loadbalancer
65+
lifecycle
66+
dbcluster
67+
dbcluster_nodes
68+
stats
69+
docker_servers
70+
5871
[base:children]
5972
docker_servers
6073

inc_test_loadbalancer_tasklist.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
# playbook loops over:
3+
# loadbalancers
4+
# haproxy_applications (item)
5+
#
6+
# and does an url request on lodbalancer ip with vhostname as the host header
7+
8+
- name: Try to reach {{ item.vhost_name }} via https://{{ haproxy_sni_ip_restricted.ipv4 }}:443 # noqa: name[template] jinja template helps with debugging
9+
when: item.restricted is defined and item.restricted
10+
ansible.builtin.uri:
11+
url: "https://{{ haproxy_sni_ip_restricted.ipv4 }}:443/{{ item.ha_url }}"
12+
method: GET
13+
status_code: [200, 302]
14+
return_content: false
15+
validate_certs: false
16+
headers:
17+
host: "{{ item.vhost_name }}"
18+
register: result
19+
until: result.status == 200 or result.status == 302
20+
retries: 3
21+
delay: 2
22+
delegate_to: 127.0.0.1 # run check from deploy host
23+
24+
# Try to reach applications via loadbalancer without restricted ip v4
25+
- name: Try to reach {{ item.vhost_name }} via https://{{ haproxy_sni_ip.ipv4 }}:443 # noqa: name[template] jinja template helps with debugging
26+
when: item.restricted is undefined
27+
ansible.builtin.uri:
28+
url: "https://{{ haproxy_sni_ip.ipv4 }}:443/{{ item.ha_url }}"
29+
method: GET
30+
status_code: [200, 302]
31+
return_content: false
32+
validate_certs: false
33+
headers:
34+
host: "{{ item.vhost_name }}"
35+
register: result
36+
until: result.status == 200 or result.status == 302
37+
retries: 3
38+
delay: 2
39+
delegate_to: 127.0.0.1 #run check from deploy host

roles/haproxy/tasks/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
url: "https://haproxy.debian.net/bernat.debian.org.gpg"
55
dest: "/etc/apt/trusted.gpg.d/haproxy.asc"
66
mode: '0644'
7+
when: not ansible_check_mode # task reports change in check mode when there is none
78

89
- name: Add HAProxy repository to sources list
910
ansible.builtin.copy:

test_loadbalancers_playbook.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
- name: Test loadbalancer
3+
hosts: loadbalancer
4+
gather_facts: false
5+
become: false
6+
tasks:
7+
8+
- name: Read vars from secrets file
9+
ansible.builtin.include_vars: "{{ inventory_dir }}/secrets/secrets.yml"
10+
no_log: true
11+
tags:
12+
- always
13+
14+
- name: Include task list in play
15+
ansible.builtin.include_tasks:
16+
file: inc_test_loadbalancer_tasklist.yml
17+
with_items: "{{ haproxy_applications }}"

0 commit comments

Comments
 (0)