Skip to content

Commit

Permalink
handle 'nginx -t' failures with custom message
Browse files Browse the repository at this point in the history
Co-authored-by: Jane Sandberg <[email protected]>
  • Loading branch information
acozine and sandbergja committed Feb 8, 2024
1 parent 2ad77a4 commit d337e8a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions roles/nginxplus/tasks/validate.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
---
- name: nginxplus | make sure nginx configs are valid
# ignoring errors so we can provide a custom message if validation fails
command: /usr/sbin/nginx -t
changed_when: false
ignore_errors: true
become: true
tags: always
register: validate_config_msg

- name: display full failure message
ansible.builtin.debug:
var: validate_config_msg
when: validate_config_msg.rc != 0 or 'test failed' in validate_config_msg.stderr

- name: fail with message if nginx -t errors out
ansible.builtin.fail:
msg: "Nginx config update failed. Time to get a human involved, please restore from /tmp/nginx_backup."
when: validate_config_msg.rc != 0 or 'test failed' in validate_config_msg.stderr

0 comments on commit d337e8a

Please sign in to comment.