Skip to content

Commit ce3c0a8

Browse files
committed
feat(ansible): add playbook to update nginx
1 parent 225a7bc commit ce3c0a8

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
File renamed without changes.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
- name: Update NGINX Config and reload server
3+
hosts: '{{ variable_host | default("null") }}'
4+
become: true
5+
serial: 1
6+
7+
tasks:
8+
- name: Add a delay to stagger the reloads
9+
pause:
10+
seconds: "{{ 10 + (ansible_play_batch.index | random(seed=inventory_hostname)) }}"
11+
12+
- name: Update Git Repository
13+
git:
14+
repo: https://github.com/freeCodeCamp/nginx-config.git
15+
dest: /etc/nginx
16+
clone: false
17+
update: true
18+
force: true
19+
single_branch: true
20+
version: master
21+
accept_hostkey: true
22+
register: git_update
23+
24+
- name: Check if Git Repository was Updated
25+
debug:
26+
msg:
27+
'Git Repository was updated, you should run the pipeline for a new
28+
deployment.'
29+
when: git_update.changed
30+
31+
- name: Check NGINX Config
32+
shell:
33+
chdir: /etc/nginx
34+
cmd: nginx -t
35+
register: nginx_config_check
36+
ignore_errors: true
37+
38+
- name: Notify if NGINX Config Check Failed
39+
debug:
40+
msg: "NGINX configuration check failed! Please review the configuration before proceeding."
41+
when: nginx_config_check.rc != 0
42+
43+
- name: Start NGINX
44+
service:
45+
name: nginx
46+
state: started
47+
enabled: true
48+
when: nginx_config_check.rc == 0
49+
50+
- name: Reload NGINX
51+
shell:
52+
chdir: /etc/nginx
53+
cmd: nginx -s 'reload'
54+
when: nginx_config_check.rc == 0

0 commit comments

Comments
 (0)