-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlb.yml
executable file
·81 lines (80 loc) · 1.89 KB
/
lb.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/local/bin/ansible-playbook
- hosts: backend
tasks:
- name: Install python in target nodes
command:
cmd: yum install python3 -y
creates: /usr/bin/python3
- name: Install httpd
package:
name: httpd
state: present
- name: Copy files
copy:
content: "I am {{ ansible_facts.default_ipv4['address'] }}"
dest: /var/www/html/index.html
notify: Restart httpd
- name: Start firewall service
service:
name: firewalld
state: started
enabled: yes
- name: Add firewall rule
firewalld:
port: 80/tcp
immediate: yes
permanent: yes
state: enabled
handlers:
- name: Restart httpd
service:
name: httpd
state: restarted
enabled: yes
- hosts: lb
vars:
config_file: /etc/haproxy/haproxy.cfg
tasks:
- name: Install Python 3
command:
cmd: yum install python3 -y
creates: /usr/bin/python3
- name: Install HAProxy
package:
name: haproxy
state: present
- name: Bind haproxy with port 80
replace:
path: "{{ config_file }}"
regexp: bind \*:5000
replace: bind *:80
- name: Removing predefined backend servers
lineinfile:
regexp: " server app.*"
dest: /etc/haproxy/haproxy.cfg
insertafter: "backend app"
state: absent
- name: Adding new backend servers
lineinfile:
line: " server {{ item }} {{ item }}:80 check"
dest: "{{ config_file }}"
insertafter: "backend app\n balance"
loop: "{{ groups.backend }}"
notify: Restart haproxy
- name: Start firewall service
service:
name: firewalld
state: started
enabled: yes
- name: Add firewall rule
firewalld:
port: 80/tcp
immediate: yes
permanent: yes
state: enabled
handlers:
- name: Restart haproxy
service:
name: haproxy
state: restarted
enabled: yes