-
Notifications
You must be signed in to change notification settings - Fork 0
/
site.yaml
139 lines (115 loc) · 3.16 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
- hosts: webservers
become: true
gather_facts: true
tasks:
- name: Copy Flask app to remote server
copy:
src: ./application2.py
dest: /home/ubuntu/application2.py
mode: '0755'
- name: Install Python 3 and pip
become: true
apt:
name:
- python3
- python3-pip
update_cache: yes
- name: Install Flask
become: true
pip:
name: Flask
- name: Create systemd unit file for application2
copy:
src: ./application2.service
dest: /etc/systemd/system/application2.service
mode: '0777'
- name: Reload systemd
systemd:
daemon_reload: yes
- name: Enable and start application2 service
systemd:
name: application2.service
state: started
enabled: yes
- name: Installing nginx
apt:
name: nginx
state: latest
update_cache: true
- name: Install SNMPd
become: true
apt:
name: snmpd
state: present
update_cache: true
- name: Configuring snmpd
template:
src: snmpd.conf
dest: /etc/snmp/snmpd.conf
- name: Restart snmpd
ansible.builtin.systemd:
name: snmpd
state: restarted
- name: apt update
apt:
update_cache: true
- hosts: HAproxy
become: true
gather_facts: true
tasks:
- name: Update apt cache
apt:
update_cache: yes
- name: Install curl
apt:
name: curl
state: latest
- name: Install HAProxy
apt:
name: haproxy
state: latest
- name: Install Nginx
apt:
name: nginx
state: latest
- name: Copy Nginx configuration
become: true
template:
src: ./nginx.conf.j2
dest: /etc/nginx/nginx.conf
owner: root
group: root
mode: '0644'
- name: configure nginx udp port
template:
src: ./port.conf
dest: /etc/nginx/sites-available/default
- name: Restart nginx
ansible.builtin.shell:
cmd: "sudo service nginx restart"
- name: Configure HAProxy
template:
src: ./haproxy.cfg.j2
dest: /etc/haproxy/haproxy.cfg
vars:
haproxy_ip: "{{ hostvars['HAproxy']['ansible_default_ipv4']['address'] }}"
when: "'ansible_default_ipv4' in hostvars['HAproxy']"
- name: Restart haproxy
ansible.builtin.shell:
cmd: "sudo service haproxy restart"
- name: Test deployed application
uri:
url: "http://{{ hostvars['HAproxy']['ansible_host'] | default(hostvars['HAproxy']['ansible_default_ipv4']['address']) }}:80"
return_content: yes
status_code: 200
validate_certs: no
register: response
retries: 3
delay: 10
- name: Verify application response
assert:
that:
- "'Serving from' in response.content"
- "'Serving from' in response.content"
- "'Serving from' in response.content"
when: response is defined and response.status == 200