-
Notifications
You must be signed in to change notification settings - Fork 356
/
Copy pathinstall-source.yml
480 lines (420 loc) · 14.9 KB
/
install-source.yml
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
---
- name: Check for build tools
when: nginx_install_source_build_tools | bool
block:
- name: (Alpine Linux) Install build tools
community.general.apk:
name:
- alpine-sdk
- build-base
- git
- openrc
- perl
- python3
- linux-headers
- tar
- wget
update_cache: true
when: ansible_facts['os_family'] == 'Alpine'
- name: (AlmaLinux/Amazon Linux/Oracle Linux/RHEL/Rocky Linux) Set up build tools
when: ansible_facts['os_family'] == 'RedHat'
block:
- name: (RHEL 8) Install Python 3
ansible.builtin.yum:
name:
- python3
- python3-pip
- python3-devel
update_cache: true
when: ansible_facts['distribution_major_version'] is version('8', '==')
- name: (RHEL 8) Set Python 3 as default
community.general.alternatives:
name: python
path: /usr/bin/python3
link: /usr/bin/python
when: ansible_facts['distribution_major_version'] is version('8', '==')
- name: (AlmaLinux/Amazon Linux/Oracle Linux/RHEL/Rocky Linux) Install build tools
ansible.builtin.yum:
name:
- ca-certificates
- gcc
- gcc-c++
- gd
- gd-devel
- glibc
- glibc-common
- make
- perl-core
- tar
- unzip
- wget
- zlib-devel
update_cache: true
- name: (Debian/Ubuntu) Install build tools
ansible.builtin.apt:
name:
- build-essential
- checkinstall
- libtemplate-perl
- python3-minimal
- perl
- tar
- zlib1g-dev
update_cache: true
when: ansible_facts['os_family'] == 'Debian'
- name: (SLES) Install build tools
community.general.zypper:
name:
- awk
- gcc
- gzip
- make
- tar
- zlib-devel
update_cache: true
when: ansible_facts['os_family'] == 'Suse'
- name: Check for source installs
block:
- name: Check for PCRE install
ansible.builtin.stat:
path: /tmp/pcre-{{ pcre_version }}
register: pcre_result
- name: Check for ZLib install
ansible.builtin.stat:
path: /tmp/zlib-{{ zlib_version }}
register: zlib_result
- name: Check for OpenSSL install
ansible.builtin.stat:
path: /tmp/openssl-{{ openssl_version }}
register: openssl_result
- name: Install PCRE dependecy from package
when: not nginx_install_source_pcre | bool
block:
- name: (Alpine Linux) Install PCRE dependency from package
community.general.apk:
name: "{{ (pcre_release == 2) | ternary('pcre2-dev', 'pcre-dev') }}"
update_cache: true
when: ansible_facts['os_family'] == 'Alpine'
- name: (AlmaLinux/Amazon Linux/Oracle Linux/RHEL/Rocky Linux) Install PCRE dependency from package
ansible.builtin.yum:
name: "{{ (pcre_release == 2) | ternary('pcre2-devel', 'pcre-devel') }}"
update_cache: true
when: ansible_facts['os_family'] == 'RedHat'
- name: (Debian/Ubuntu) Install PCRE dependency from package
ansible.builtin.apt:
name: "{{ (pcre_release == 2) | ternary('libpcre2-dev', 'libpcre3-dev') }}"
update_cache: true
when: ansible_facts['os_family'] == 'Debian'
- name: (SLES) Install PCRE dependency from package
community.general.zypper:
name: "{{ (pcre_release == 2) | ternary('pcre2-devel', 'pcre-devel') }}"
update_cache: true
when: ansible_facts['os_family'] == 'Suse'
- name: Install PCRE dependence from source
when:
- not pcre_result['stat']['exists'] | bool
- nginx_install_source_pcre | bool
- not ansible_check_mode | bool
block:
- name: Download PCRE dependency
ansible.builtin.get_url:
url: "{{ (pcre_release == 2) | ternary('https://github.com/PCRE2Project/pcre2/releases/download/pcre2-' ~ pcre_version ~ '/pcre2-' ~ pcre_version ~ '.tar.gz', 'https://ftp.exim.org/pub/pcre/pcre-' ~ pcre_version ~ '.tar.gz') }}"
dest: /tmp
mode: "0600"
register: pcre_source
- name: Ensure PCRE directory exists
ansible.builtin.file:
path: /tmp/pcre-{{ pcre_version }}
state: directory
mode: "0700"
- name: Unpack PCRE dependency
ansible.builtin.unarchive:
copy: false
src: "{{ pcre_source['dest'] }}"
dest: /tmp/pcre-{{ pcre_version }}/
mode: "0700"
extra_opts: [--strip-components=1]
- name: Configure PCRE dependency
ansible.builtin.command:
cmd: ./configure
chdir: /tmp/pcre-{{ pcre_version }}
creates: /tmp/makefile
- name: Make PCRE dependency
community.general.make:
chdir: /tmp/pcre-{{ pcre_version }}
- name: Install PCRE dependency
community.general.make:
chdir: /tmp/pcre-{{ pcre_version }}
target: install
- name: Install ZLib dependency from package
when: not nginx_install_source_zlib | bool
block:
- name: (Alpine Linux) Install ZLib dependency from package
community.general.apk:
name: zlib-dev
update_cache: true
when: ansible_facts['os_family'] == 'Alpine'
- name: (AlmaLinux/Amazon Linux/Oracle Linux/RHEL/Rocky Linux) Install ZLib dependency from package
ansible.builtin.yum:
name: zlib-devel
update_cache: true
when: ansible_facts['os_family'] == 'RedHat'
- name: (Debian/Ubuntu) Install ZLib dependency from package
ansible.builtin.apt:
name: zlib1g-dev
update_cache: true
when: ansible_facts['os_family'] == 'Debian'
- name: (SLES) Install ZLib dependency from package
community.general.zypper:
name: zlib-devel
update_cache: true
when: ansible_facts['os_family'] == 'Suse'
- name: Install ZLib dependency from source
when:
- not zlib_result['stat']['exists'] | bool
- nginx_install_source_zlib | bool
- not ansible_check_mode | bool
block:
- name: Download ZLib dependency
ansible.builtin.get_url:
url: https://github.com/madler/zlib/releases/download/v{{ zlib_version }}/zlib-{{ zlib_version }}.tar.gz
dest: /tmp
mode: "0600"
register: zlib_source
- name: Ensure ZLib directory exists
ansible.builtin.file:
path: /tmp/zlib-{{ zlib_version }}
state: directory
mode: "0700"
- name: Unpack ZLib dependency
ansible.builtin.unarchive:
copy: false
src: "{{ zlib_source['dest'] }}"
dest: /tmp/zlib-{{ zlib_version }}
mode: "0700"
extra_opts: [--strip-components=1]
- name: Configure ZLib dependency
ansible.builtin.command:
cmd: ./configure
chdir: /tmp/zlib-{{ zlib_version }}
creates: /tmp/makefile
- name: Make ZLib dependency
community.general.make:
chdir: /tmp/zlib-{{ zlib_version }}
- name: Install ZLib dependency
community.general.make:
chdir: /tmp/zlib-{{ zlib_version }}
target: install
- name: Install OpenSSL dependency from package
when: not nginx_install_source_openssl | bool
block:
- name: (Alpine Linux) Install OpenSSL dependency from package
community.general.apk:
name: openssl-dev
update_cache: true
when: ansible_facts['os_family'] == 'Alpine'
- name: (AlmaLinux/Amazon Linux/Oracle Linux/RHEL/Rocky Linux) Install OpenSSL dependency from package
ansible.builtin.yum:
name: openssl-devel
update_cache: true
when: ansible_facts['os_family'] == 'RedHat'
- name: (Debian/Ubuntu) Install OpenSSL dependency from package
ansible.builtin.apt:
name: libssl-dev
update_cache: true
when: ansible_facts['os_family'] == 'Debian'
- name: (SLES) Install OpenSSL dependency from package
community.general.zypper:
name: openssl-devel
update_cache: true
when: ansible_facts['os_family'] == 'Suse'
- name: Install OpenSSL dependency from source
when:
- not openssl_result['stat']['exists'] | bool
- nginx_install_source_openssl | bool
- not ansible_check_mode | bool
block:
- name: Download OpenSSL dependency
ansible.builtin.get_url:
url: https://github.com/openssl/openssl/archive/refs/tags/openssl-{{ openssl_version }}.tar.gz
dest: /tmp/{{ openssl_version }}.tar.gz
mode: "0600"
register: openssl_source
- name: Ensure OpenSSL directory exists
ansible.builtin.file:
path: /tmp/openssl-{{ openssl_version }}
state: directory
mode: "0700"
- name: Unpack OpenSSL dependency
ansible.builtin.unarchive:
copy: false
src: "{{ openssl_source['dest'] }}"
dest: /tmp/openssl-{{ openssl_version }}
mode: "0700"
extra_opts: [--strip-components=1]
- name: Configure OpenSSL dependency
ansible.builtin.command:
cmd: ./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl shared zlib
chdir: /tmp/openssl-{{ openssl_version }}
creates: /tmp/makefile
- name: Make OpenSSL dependency
community.general.make:
chdir: /tmp/openssl-{{ openssl_version }}
- name: Install OpenSSL dependency
community.general.make:
chdir: /tmp/openssl-{{ openssl_version }}
target: install
- name: Get latest NGINX version
when: nginx_version is undefined
block:
- name: Fetch NGINX latest version
ansible.builtin.uri:
url: https://version.nginx.com/nginx/{{ nginx_branch }}
return_content: true
check_mode: false
register: nginx_latest_version
- name: Set NGINX version
ansible.builtin.set_fact:
nginx_version: "{{ (nginx_latest_version['content'] | regex_search('([0-9]+\\.){2}[0-9]+')) }}"
- name: Check for NGINX install
ansible.builtin.stat:
path: /usr/sbin/nginx
follow: true
register: nginx_result
- name: Add NGINX group
ansible.builtin.group:
name: nginx
- name: Add NGINX user
ansible.builtin.user:
name: nginx
group: nginx
comment: nginx user
home: /var/cache/nginx
shell: /sbin/nologin
- name: Install NGINX
when:
- not nginx_result['stat']['exists'] | bool
- not ansible_check_mode | bool
block:
- name: Download NGINX
ansible.builtin.get_url:
url: https://nginx.org/download/nginx-{{ nginx_version }}.tar.gz
dest: /tmp/nginx-{{ nginx_version }}.tar.gz
mode: "0600"
register: nginx_source
- name: Unpack NGINX
ansible.builtin.unarchive:
copy: false
src: "{{ nginx_source.dest }}"
dest: /tmp
mode: "0755"
- name: Set static modules
ansible.builtin.set_fact:
nginx_install_source_static_modules: "{{ nginx_install_source_static_modules | default('') + ' --with-' + item }}"
loop: "{{ nginx_static_modules }}"
- name: Configure NGINX
ansible.builtin.command:
cmd: >-
./configure
--conf-path=/etc/nginx/nginx.conf
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log
--lock-path=/var/lock/nginx.lock
--modules-path=/usr/lib/nginx/modules
--prefix=/usr
--pid-path=/var/run/nginx.pid
--user=nginx
--with-mail=dynamic
--with-stream
{{ nginx_install_source_pcre | ternary('--with-pcre=../pcre-' + pcre_version | string, '') }}
{{ nginx_install_source_zlib | ternary('--with-zlib=../zlib-' + zlib_version | string, '') }}
{{ nginx_install_source_openssl | ternary('--with-openssl=../openssl-' + openssl_version | string, '') }}
{{ nginx_install_source_static_modules | default('') }}
chdir: /tmp/nginx-{{ nginx_version }}
creates: /tmp/makefile
register: nginx_configure
- name: Make NGINX
community.general.make:
chdir: /tmp/nginx-{{ nginx_version }}
- name: Install NGINX
community.general.make:
chdir: /tmp/nginx-{{ nginx_version }}
target: install
- name: Set up systemd
when: ansible_facts['service_mgr'] == 'systemd'
notify: (Handler) Run NGINX
block:
- name: Upload systemd NGINX service file
ansible.builtin.copy:
src: services/nginx.systemd
dest: "{{ (ansible_facts['os_family'] == 'Suse') | ternary('usr/lib/systemd/system/nginx.service', '/lib/systemd/system/nginx.service') }}"
owner: root
group: root
mode: "0644"
- name: Enable systemd NGINX service file
ansible.builtin.systemd:
daemon_reload: true
name: nginx
state: restarted
enabled: true
- name: Set up Upstart
when: ansible_facts['service_mgr'] == 'upstart'
notify: (Handler) Run NGINX
block:
- name: Upload Upstart NGINX service file
ansible.builtin.copy:
src: services/nginx.upstart
dest: /etc/init.d/nginx
owner: root
group: root
mode: "0755"
- name: Upload Upstart NGINX service conf file
ansible.builtin.copy:
src: services/nginx.conf.upstart
dest: /etc/init/nginx.conf
owner: root
group: root
mode: "0644"
- name: Enable Upstart NGINX service reload # noqa no-changed-when
ansible.builtin.command: initctl reload-configuration
- name: Start Upstart NGINX service reload # noqa no-changed-when
ansible.builtin.command: nginx
- name: Upload SysVinit NGINX service file
ansible.builtin.copy:
src: services/nginx.sysvinit
dest: /etc/init.d/nginx
owner: root
group: root
mode: "0755"
when: ansible_facts['service_mgr'] == 'sysvinit'
notify: (Handler) Run NGINX
- name: Set up OpenRC
when: ansible_facts['service_mgr'] == 'openrc'
notify: (Handler) Run NGINX
block:
- name: Enable OpenRC
ansible.builtin.copy:
content: ""
dest: /run/openrc/softlevel
force: false
owner: root
mode: "0644"
- name: Upload OpenRC NGINX service file
ansible.builtin.copy:
src: services/nginx.openrc
dest: /etc/init.d/nginx
owner: root
group: root
mode: "0755"
- name: Enable OpenRC NGINX service # noqa no-changed-when
ansible.builtin.command: rc-update add nginx default
- name: Cleanup downloads
ansible.builtin.file:
path: "{{ item }}"
state: absent
loop:
- "{{ pcre_source['dest'] }}"
- "{{ zlib_source['dest'] }}"
- "{{ openssl_source['dest'] }}"
- "{{ nginx_source['dest'] }}"
when: item is defined