Skip to content

Commit 3991627

Browse files
committed
Some role updates
1 parent 77fffb8 commit 3991627

5 files changed

Lines changed: 310 additions & 23 deletions

File tree

README.md

Lines changed: 292 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,314 @@
1-
Role Name
1+
Ansible-openresty/nginx role
22
=========
33

4-
A brief description of the role goes here.
4+
Generic role to deploy install openresty/nginx servers. Extract configuration outside templates and make sure we can configure almost anything.
55

6-
Requirements
7-
------------
8-
9-
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
106

117
Role Variables
128
--------------
139

14-
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
10+
```
11+
---
12+
13+
openresty_variant: openresty
14+
15+
openresty_repo_url: "{{ _openresty_repo_url }}"
16+
openresty_repo_key: "{{ _openresty_repo_key }}"
17+
openresty_server_pkg: "{{ _openresty_server_pkg }}"
18+
openresty_service: "{{ _openresty_server_service }}"
19+
20+
openresty_packages:
21+
- wget
22+
- gnupg
23+
- ca-certificates
24+
- software-properties-common
25+
26+
openresty_conf_dir: "{{ openresty_base_dir }}/conf.d"
27+
28+
openresty_pid_dir: "{{ _openresty_pid_dir }}"
29+
openresty_pid_file: "{{ openresty_pid_dir }}/nginx.pid"
30+
31+
openresty_log_dir: /var/log/nginx
32+
openresty_root_dir: "{{ _openresty_root_dir }}"
33+
34+
35+
openresty_systemd_service_path: "{{ _openresty_systemd_service_path }}"
36+
openresty_systemd_service: "{{ _openresty_systemd_service }}"
37+
38+
openresty_server_user: www-data
39+
openresty_server_group: www-data
40+
41+
openresty_ssl_dhparam_size: 2048
42+
openresty_ssl_dhparam_file: "{{ openresty_base_dir }}/dh{{ openresty_ssl_dhparam_size }}.pem"
43+
44+
openresty_ssl_selfsigned_generate: true
45+
openresty_ssl_selfsigned_name: default
46+
47+
openresty_ssl_files: {}
48+
# - certificate: "{{ openresty_ssl_cert_dir }}/ansible.com.crt"
49+
# certificate_value:
50+
# key: "{{ openresty_ssl_key_dir }}/ansible.com.key"
51+
# key_value:
52+
# - certificate: "{{ openresty_ssl_cert_dir }}/test2.com.crt"
53+
# certificate_value: "{{ ssl_test2_cert }}"
54+
# key: "{{ openresty_ssl_key_dir }}/test2.com.key"
55+
# key_value: "{{ ssl_test2.com_key }}"
56+
openresty_main_template:
57+
global_conf:
58+
user: "{{ openresty_server_user }}"
59+
worker_processes: auto
60+
#worker_rlimit_nofile: 1024
61+
error_log: "{{ openresty_log_dir }}/error.log debug"
62+
pid: "{{ openresty_pid_file }}"
63+
event_conf:
64+
worker_connections: 1024
65+
multi_accept: 'on'
66+
http_conf:
67+
include: "{{ openresty_base_dir }}/mime.types"
68+
default_type: application/octet-stream
69+
keepalive_timeout: 65
70+
access_log: 'off'
71+
log_format: main '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"'
72+
73+
sendfile: 'on'
74+
tcp_nopush: 'on'
75+
tcp_nodelay: 'on'
76+
77+
server_tokens: 'off'
78+
client_max_body_size: 20m
79+
client_body_buffer_size: 128k
80+
index: index.php index.htm index.html
81+
82+
gzip: 'on'
83+
gzip_disable: "MSIE [1-6].(?!.*SV1)"
84+
gzip_vary: 'on'
85+
gzip_proxied: any
86+
gzip_comp_level: 6
87+
gzip_buffers: 16 8k
88+
gzip_http_version: 1.1
89+
gzip_types: text/plain text/css text/javascript text/xml application/json application/x-javascript application/xml application/xml+rss application/octet-stream
90+
91+
ssl_protocols: 'TLSv1.2 TLSv1.3'
92+
ssl_session_tickets: 'off'
93+
ssl_prefer_server_ciphers: 'on'
94+
ssl_ciphers: "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256"
95+
ssl_dhparam: "{{ openresty_ssl_dhparam_file }}"
96+
97+
openresty_params:
98+
- filename: fastcgi_params
99+
directive: fastcgi_param
100+
include: true
101+
vars:
102+
QUERY_STRING: $query_string
103+
REQUEST_METHOD: $request_method
104+
CONTENT_TYPE: $content_type
105+
CONTENT_LENGTH: $content_length
106+
107+
SCRIPT_FILENAME: $request_filename
108+
SCRIPT_NAME: $fastcgi_script_name
109+
REQUEST_URI: $request_uri
110+
DOCUMENT_URI: $document_uri
111+
DOCUMENT_ROOT: $document_root
112+
SERVER_PROTOCOL: $server_protocol
113+
114+
GATEWAY_INTERFACE: GI/1.1
115+
SERVER_SOFTWARE: nginx/$nginx_version
116+
117+
REMOTE_ADDR: $remote_addr
118+
REMOTE_PORT: $remote_port
119+
SERVER_ADDR: $server_addr
120+
SERVER_PORT: $server_port
121+
SERVER_NAME: $server_name
122+
123+
HTTPS: $https
124+
125+
REDIRECT_STATUS: 200
126+
- filename: proxy_params
127+
directive: proxy_set_header
128+
include: false
129+
vars:
130+
Host: $host
131+
X-Real-IP: $remote_addr
132+
X-Forwarded-For: $proxy_add_x_forwarded_for
133+
- filename: uwsgi_params
134+
directive: uwsgi_param
135+
include: false
136+
vars:
137+
QUERY_STRING: $query_string
138+
REQUEST_METHOD: $request_method
139+
CONTENT_TYPE: $content_type
140+
CONTENT_LENGTH: $content_length
141+
142+
REQUEST_URI: $request_uri
143+
PATH_INFO: $document_uri
144+
DOCUMENT_ROOT: $document_root
145+
SERVER_PROTOCOL: $server_protocol
146+
UWSGI_SCHEME: $scheme
147+
148+
REMOTE_ADDR: $remote_addr
149+
REMOTE_PORT: $remote_port
150+
SERVER_PORT: $server_port
151+
SERVER_NAME: $server_name
152+
- filename: error_codes
153+
include: true
154+
data: |
155+
map $status $status_text {
156+
400 'Bad Request';
157+
401 'Unauthorized';
158+
402 'Payment Required';
159+
403 'Forbidden';
160+
404 'Not Found';
161+
405 'Method Not Allowed';
162+
406 'Not Acceptable';
163+
407 'Proxy Authentication Required';
164+
408 'Request Timeout';
165+
409 'Conflict';
166+
410 'Gone';
167+
411 'Length Required';
168+
412 'Precondition Failed';
169+
413 'Payload Too Large';
170+
414 'URI Too Long';
171+
415 'Unsupported Media Type';
172+
416 'Range Not Satisfiable';
173+
417 'Expectation Failed';
174+
418 'I\'m a teapot';
175+
421 'Misdirected Request';
176+
422 'Unprocessable Entity';
177+
423 'Locked';
178+
424 'Failed Dependency';
179+
426 'Upgrade Required';
180+
428 'Precondition Required';
181+
429 'Too Many Requests';
182+
431 'Request Header Fields Too Large';
183+
451 'Unavailable For Legal Reasons';
184+
500 'Internal Server Error';
185+
501 'Not Implemented';
186+
502 'Bad Gateway';
187+
503 'Service Unavailable';
188+
504 'Gateway Timeout';
189+
505 'HTTP Version Not Supported';
190+
506 'Variant Also Negotiates';
191+
507 'Insufficient Storage';
192+
508 'Loop Detected';
193+
510 'Not Extended';
194+
511 'Network Authentication Required';
195+
default 'Something is wrong';
196+
}
197+
198+
openresty_addtional_params: []
199+
200+
openresty_default_listen_options: "{{ _openrest_default_listen_options + openresty_additional_listen_options }}"
201+
openresty_additional_listen_options: []
202+
203+
openresty_default_sites_conf:
204+
- server_name: _
205+
root_dir: "{{ openresty_root_dir }}"
206+
error_pages:
207+
- 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 421 422 423 424 426 428 429 431 451 /40x.html
208+
- 500 501 502 503 504 505 506 507 508 510 511 /50x.html
209+
servers:
210+
- listen:
211+
port: 80
212+
options: "{{ openresty_default_listen_options | join(' ') }}"
213+
locations:
214+
- path: ~ /nginx_status
215+
conf:
216+
- stub_status: 'on'
217+
- access_log: 'off'
218+
- allow: 127.0.0.1
219+
- allow: 10.0.0.251/32
220+
- allow: 10.0.0.252/32
221+
- allow: 10.0.0.25/32
222+
- deny: all
223+
- path: /
224+
conf:
225+
- return: 404
226+
- path: = /50x.html
227+
conf:
228+
- ssi: 'on'
229+
- internal:
230+
- root: "{{ openresty_root_dir }}/errors"
231+
- path: = /40x.html
232+
conf:
233+
- ssi: 'on'
234+
- internal:
235+
- root: "{{ openresty_root_dir }}/errors"
236+
- listen:
237+
port: 443
238+
options: "ssl {{ openresty_default_listen_options | join(' ') }}"
239+
ssl:
240+
certificate: "{{ openresty_ssl_cert_dir }}/{{ openresty_ssl_selfsigned_name }}.crt"
241+
key: "{{ openresty_ssl_key_dir }}/{{ openresty_ssl_selfsigned_name }}.pem"
242+
locations:
243+
- path: ~ /nginx_status
244+
conf:
245+
- stub_status: 'on'
246+
- access_log: 'off'
247+
- allow: 127.0.0.1
248+
- allow: 10.0.0.251/32
249+
- allow: 10.0.0.252/32
250+
- allow: 10.0.0.25/32
251+
- deny: all
252+
- path: /
253+
conf:
254+
- return: 404
255+
- path: = /50x.html
256+
conf:
257+
- ssi: 'on'
258+
- internal:
259+
- root: "{{ openresty_root_dir }}/errors"
260+
- path: = /40x.html
261+
conf:
262+
- ssi: 'on'
263+
- internal:
264+
- root: "{{ openresty_root_dir }}/errors"
265+
openresty_sites_conf: []
266+
```
15267

16268
Dependencies
17269
------------
18270

19-
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
271+
Requires role:
272+
- name: ansible.systemd-service
273+
scm: git
274+
src: https://github.com/lablabs/ansible-role-systemd-service.git
275+
version: 1.0.0
276+
path: ./dist
277+
20278

21279
Example Playbook
22280
----------------
23281

24282
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
25283

26-
- hosts: servers
27-
roles:
28-
- { role: username.rolename, x: 42 }
284+
```
285+
- name: "Deploy Openresty to {{ play_hosts }} static servers"
286+
hosts: web
287+
become: true
288+
tags: play:web
289+
environment: "{{ deploy_env_vars | default({}) }}"
290+
tasks:
291+
292+
- name: Disable Healthcheck monitor on a server
293+
changed_when: false
294+
iptables:
295+
chain: INPUT
296+
protocol: tcp
297+
destination_port: "{{ item }}"
298+
jump: DROP
299+
state: present
300+
with_items:
301+
- "80"
302+
- "443"
303+
304+
- include_role:
305+
name: deploy.openresty
306+
apply:
307+
tags: role:deploy.openresty
308+
tags: role:deploy.openresty
309+
```
29310

30311
License
31312
-------
32313

33314
BSD
34-
35-
Author Information
36-
------------------
37-
38-
An optional section for the role authors to include contact information, or a website (HTML is not allowed).

defaults/main.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ openresty_packages:
1515

1616
openresty_conf_dir: "{{ openresty_base_dir }}/conf.d"
1717

18-
openresty_pid_dir: /var/run/nginx
18+
openresty_pid_dir: "{{ _openresty_pid_dir }}"
19+
openresty_pid_file: "{{ openresty_pid_dir }}/nginx.pid"
20+
1921
openresty_log_dir: /var/log/nginx
2022
openresty_root_dir: "{{ _openresty_root_dir }}"
2123

24+
2225
openresty_systemd_service_path: "{{ _openresty_systemd_service_path }}"
2326
openresty_systemd_service: "{{ _openresty_systemd_service }}"
2427

@@ -46,7 +49,7 @@ openresty_main_template:
4649
worker_processes: auto
4750
#worker_rlimit_nofile: 1024
4851
error_log: "{{ openresty_log_dir }}/error.log debug"
49-
pid: "{{ openresty_pid_dir }}/nginx.pid"
52+
pid: "{{ openresty_pid_file }}"
5053
event_conf:
5154
worker_connections: 1024
5255
multi_accept: 'on'

tasks/install.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@
2929
path: "{{ item.path }}"
3030
owner: "{{ item.owner | default(omit) }}"
3131
group: "{{ item.group | default(omit) }}"
32+
recurse: "{{ item.recurse | default(omit) }}"
3233
with_items:
3334
- path: "{{ openresty_base_dir }}"
35+
36+
- path: "{{ openresty_pid_dir }}"
37+
recurse: true
38+
3439
- path: "{{ openresty_log_dir }}"
3540
owner: "{{ openresty_server_user }}"
3641
group: "{{ openresty_server_group }}"
@@ -41,3 +46,4 @@
4146
- path: "{{ openresty_ssl_key_dir }}"
4247
- path: "{{ openresty_ssl_cert_dir }}"
4348
- path: "{{ openresty_ssl_csr_dir }}"
49+

vars/nginx.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ _openresty_server_pkg: nginx
55
_openresty_server_service: nginx
66

77
_openresty_root_dir: /usr/share/nginx/html
8+
_openresty_pid_dir: /var/run/nginx
89

910
_openrest_default_listen_options:
1011
- default_server
@@ -21,11 +22,11 @@ _openresty_systemd_service:
2122

2223
Service:
2324
Type: forking
24-
PIDFile: "{{ openresty_pid_dir }}/nginx.pid"
25+
PIDFile: "{{ openresty_pid_file }}"
2526
ExecStartPre: /usr/sbin/nginx -c {{ openresty_base_dir }}/nginx.conf -t -q -g 'daemon on; master_process on;'
2627
ExecStart: /usr/sbin/nginx -c {{ openresty_base_dir }}/nginx.conf -g 'daemon on; master_process on;'
2728
ExecReload: /usr/sbin/nginx -c {{ openresty_base_dir }}/nginx.conf -g 'daemon on; master_process on;' -s reload
28-
ExecStop: "-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile {{ openresty_pid_dir }}/nginx.pid"
29+
ExecStop: "-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile {{ openresty_pid_file }}"
2930
TimeoutStopSec: 5
3031
KillMode: mixed
3132

0 commit comments

Comments
 (0)