Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions ansible/play-oldeworld--update-nginx-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
- name: Update NGINX Config and reload server
hosts: '{{ variable_host | default("null") }}'
become: true
serial: 1

tasks:
- name: Add a delay to stagger the reloads
pause:
seconds: "{{ 10 + (ansible_play_batch.index | random(seed=inventory_hostname)) }}"

- name: Update Git Repository
git:
repo: https://github.com/freeCodeCamp/nginx-config.git
dest: /etc/nginx
clone: false
update: true
force: true
single_branch: true
version: master
accept_hostkey: true
register: git_update

- name: Check if Git Repository was Updated
debug:
msg:
'Git Repository was updated, you should run the pipeline for a new
deployment.'
when: git_update.changed

- name: Check NGINX Config
shell:
chdir: /etc/nginx
cmd: nginx -t
register: nginx_config_check
ignore_errors: true

- name: Notify if NGINX Config Check Failed
debug:
msg: "NGINX configuration check failed! Please review the configuration before proceeding."
when: nginx_config_check.rc != 0

- name: Start NGINX
service:
name: nginx
state: started
enabled: true
when: nginx_config_check.rc == 0

- name: Reload NGINX
shell:
chdir: /etc/nginx
cmd: nginx -s 'reload'
when: nginx_config_check.rc == 0