-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLB with WebServer in Local VMs
76 lines (59 loc) · 1.47 KB
/
LB with WebServer in Local VMs
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
# cat /root/ip.txt
[mylb]
192.168.0.120 ansible_ssh_user=root ansible_ssh_pass=redhat
[myweb]
192.168.0.122 ansible_ssh_user=root ansible_ssh_pass=redhat
192.168.0.123 ansible_ssh_user=root ansible_ssh_pass=redhat
192.168.0.124 ansible_ssh_user=root ansible_ssh_pass=redhat
=========================================================================
-> Some changes in local "haproxy.cfg" file.
# -----------------------------------
# round robin balancing ...
# -----------------------------------
backend app
balance roundrobin
{% for i in groups['myweb'] %}
server app{{ loop.index }} {{ i }}:80 check
{{% endfor %}}
=============================================================================
# cat index.php
<pre>
<?php
print `/usr/sbin/ifconfig`;
?>
</pre>
==============================================================
# cat mylb.yml
- hosts: myweb
tasks:
- name: "installing httpd"
package:
name: "httpd"
state: present
- name: "installing php"
package:
name: "php"
state: present
- name: "copy content"
copy:
src: "/index.php"
dest: "/var/www/html"
- name: "starting service"
service:
name: "httpd"
state: started
- hosts: mylb
tasks:
- name: "installing haproxy"
package:
name: "haproxy"
state: present
- name: "sending haproxy config file"
template:
src: "haproxy.cfg.j2"
dest: "/etc/haproxy/haproxy.cfg"
- name: "start service"
service:
name: "haproxy"
state: restarted
# ansible-playbook mylb.yml