-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathtasks_nginx.yml
More file actions
219 lines (187 loc) · 5.9 KB
/
Copy pathtasks_nginx.yml
File metadata and controls
219 lines (187 loc) · 5.9 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#
# Credits: https://raw.githubusercontent.com/StarterSquad/prudentia/develop/prudentia/tasks/nginx.yml
# based on, but refactored and improved.
#
---
- name: Nginx | Check if is present
command: test -x /usr/sbin/nginx
ignore_errors: yes
register: nginx_present
changed_when: false
tags: nginx
- block:
- name: Nginx | Install (apk)
apk: update_cache=yes state=present name=nginx
retries: 3
register: result
until: result is not failed
when: nginx_present is failed
tags: nginx
become: yes
- name: Nginx | Install (apk)
apk: state=present name=acl
retries: 3
register: result
until: result is not failed
when: nginx_present is failed
tags: nginx
become: yes
when: ansible_os_family == "Alpine"
- block:
- name: Nginx | Get acl dependency (ansible unprivileged user operations magic)
package: name="acl" state="present"
retries: 3
register: result
until: result is not failed
become: yes
tags:
- nginx
- name: Nginx | Add GPG key to apt keyring
apt_key: url=http://nginx.org/keys/nginx_signing.key state=present
retries: 3
register: result
until: result is not failed
when: nginx_present is failed
become: yes
tags:
- nginx
- name: Nginx | Add Debian apt repository
apt_repository: repo="deb http://nginx.org/packages/debian/ {{ ansible_distribution_release }} nginx"
when: ansible_os_family == "Debian" and ansible_distribution != "Ubuntu" and nginx_present is failed
tags: nginx
become: yes
- name: Nginx | Add Ubuntu apt repository
apt_repository: repo="deb http://nginx.org/packages/ubuntu/ {{ ansible_distribution_release }} nginx"
when: ansible_distribution == "Ubuntu" and nginx_present is failed
tags: nginx
become: yes
- name: Nginx | Install (apt)
apt: update-cache=yes force=yes state=present pkg=nginx
retries: 3
register: result
until: result is not failed
when: nginx_present is failed
tags: nginx
become: yes
when: ansible_os_family == "Debian"
- block:
- name: Nginx | Get acl dependency (ansible unprivileged user operations magic)
package: name="acl" state="present"
retries: 3
register: result
until: result is not failed
become: yes
tags:
- nginx
- name: Nginx | Add RPM official nginx key
rpm_key: key=http://nginx.org/keys/nginx_signing.key
retries: 3
register: result
until: result is not failed
when: ansible_distribution == 'RedHat' or ansible_distribution == 'CentOS'
tags: nginx
become: yes
- name: Nginx | add YUM official nginx repository
template: src="{{ role_dir }}/templates/nginx/nginx.repo.j2" dest=/etc/yum.repos.d/nginx.repo
when: ansible_distribution == 'RedHat' or ansible_distribution == 'CentOS'
tags: nginx
become: yes
- name: Nginx | Install (OS specific yum/dng)
package: state=present name=nginx
retries: 3
register: result
until: result is not failed
tags: nginx
become: yes
when: ansible_distribution == 'RedHat' or ansible_distribution == 'CentOS' or ansible_distribution == 'Fedora'
- name: Nginx | Create sites available/enabled directories
file: path={{ item }} state=directory mode=0755
with_items:
- /etc/nginx/sites-available
- /etc/nginx/sites-enabled
become: yes
tags:
- nginx
- name: Nginx | Configure include sites-enabled
lineinfile:
dest: /etc/nginx/nginx.conf
regexp: ".*sites-enabled.*"
line: " include /etc/nginx/sites-enabled/*;"
insertbefore: "}"
state: present
become: yes
tags:
- nginx
- name: Nginx | Disable default site
file: path="{{ item }}" state=absent
with_items:
- /etc/nginx/default.conf
- /etc/nginx/conf.d/default.conf
when: nginx_present is failed
become: yes
tags:
- nginx
- name: Nginx | Uncomment server_names_hash_bucket_size
lineinfile:
dest: /etc/nginx/nginx.conf
regexp: "^(\\s*)#\\s*server_names_hash_bucket_size"
line: "\\1server_names_hash_bucket_size 64;"
backrefs: yes
become: yes
tags:
- nginx
- name: Nginx | Patch basic settings /etc/nginx/nginx.conf
lineinfile:
dest: /etc/nginx/nginx.conf
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
insertbefore: "{{ item.insertbefore | default(omit) }}"
insertafter: "{{ item.insertafter | default(omit) }}"
backrefs: "{{ item.backrefs | default(omit) }}"
with_items: "{{ nginx_conf_properties | default([]) }}"
become: yes
tags:
- nginx
- name: Nginx | Create snippets directory
file: path={{ item }} state=directory mode=0755
with_items:
- /etc/nginx/snippets
become: yes
tags:
- nginx
- name: Nginx | Put default snippets there
copy:
src: "{{ role_dir }}/files/snippets/{{ item }}"
dest: "/etc/nginx/snippets/{{ item }}"
owner: root
group: root
mode: u=rw,g=r,o=r
with_items:
- fastcgi.conf
- fastcgi_params
- uwsgi_params
become: yes
tags:
- nginx
- name: Nginx | Add nginx user to additional groups, if needed
user: name='nginx' groups="{{ item }}" append=yes
with_items: "{{ nginx_groups | default([]) }}"
become: yes
tags:
- nginx
- name: Nginx | custom log files workaround - allow nginx user to write files into /var/log/nginx but not read
acl:
path: /var/log/nginx
entity: nginx
etype: user
permissions: wx
state: present
become: yes
tags:
- nginx
- name: Nginx | Reload configuration
service: name=nginx state=restarted enabled=yes
when: nginx_present is failed and docker_test is not defined
become: yes
tags:
- nginx