-
Notifications
You must be signed in to change notification settings - Fork 0
/
site.yaml
74 lines (59 loc) · 2.13 KB
/
site.yaml
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
---
- hosts: webservers
become: yes
tasks:
- name: Install nginx php and php-fpm
apt:
name: ['nginx', 'php', 'php-fpm']
state: present
update_cache: yes
- name: Stop Apache2 service
service:
name: apache2
state: stopped
enabled: no
- name: Create php file
become: true
copy:
dest: "/var/www/html/index.php"
content: |
<?php echo date("Y-m-d H:i:s") . " Welcome to " . gethostname() . "|" .$_SERVER['SERVER_ADDR'] .":" . $_SERVER['SERVER_PORT'] ."<br>\n"; ?>
- name: Copy nginx default config file
copy:
src: default
dest: /etc/nginx/sites-available/default
- name: Restart nginx service
become: true
service:
name=nginx
state=restarted
- hosts: webservers
tasks:
- debug: var=ansible_all_ipv4_addresses
- hosts: haproxy
become: yes
tasks:
- name: Install haproxy service
apt:
name: haproxy
state: latest
update_cache: yes
- name: Update haproxy config file
blockinfile:
path: /etc/haproxy/haproxy.cfg
block: |
frontend haproxy
bind *:80
default_backend backend_servers
backend backend_servers
balance roundrobin
mode http
option forwardfor
{% for server in groups['webservers'] %}
server {{ hostvars[server]['inventory_hostname'] }} {{ hostvars[server]['ansible_default_ipv4']['address']}}:80 check
{% endfor %}
- name: Restart haproxy service
service:
name: haproxy
state: restarted
enabled: yes