Skip to content

Commit

Permalink
Merge pull request #5 from Tinyblargon/refactor-restore
Browse files Browse the repository at this point in the history
refactor: config restore procedure
  • Loading branch information
Tinyblargon authored Dec 3, 2023
2 parents 7423b6b + 8e3b043 commit 6fa94f4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
40 changes: 24 additions & 16 deletions tasks/present.ansible.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,33 @@
file: vhosts_remove.ansible.yml
when: nginx_vhosts_remove

- name: Test nginx config
ansible.builtin.command:
cmd: nginx -t
register: nginx_test
ignore_errors: true
- name: Validate nginx config
block:
- name: Test nginx config
ansible.builtin.command:
cmd: nginx -t
changed_when: false
no_log: true
become: true
when: nginx_backup_condition
rescue:
- name: Restore nginx backup
ansible.builtin.include_tasks:
file: restore.ansible.yml
when: nginx_backup_condition
- name: Flush handlers
ansible.builtin.meta: flush_handlers
- name: Invalid nginx config
ansible.builtin.fail:
msg: "{{ ansible_failed_result.stderr_lines }}"

- name: Delete backup
ansible.builtin.file:
path: "{{ nginx_backup_file }}"
state: absent
changed_when: false
no_log: true
become: true
when: nginx_backup_condition

- name: Restore/delete nginx backup
ansible.builtin.include_tasks:
file: restore.ansible.yml
when: nginx_backup_condition

- name: Flush handlers
ansible.builtin.meta: flush_handlers

- name: Invalid nginx config
ansible.builtin.fail:
msg: "{{ nginx_test.stderr_lines }}"
when: nginx_test.failed is defined and nginx_test.failed
2 changes: 0 additions & 2 deletions tasks/restore.ansible.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
path: "{{ nginx_path }}"
state: absent
become: true
when: not nginx_test is defined or nginx_test.failed

- name: Restore backup
ansible.builtin.unarchive:
src: "{{ nginx_backup_file }}"
dest: "{{ nginx_path | dirname }}"
remote_src: true
become: true
when: not nginx_test is defined or nginx_test.failed
notify: Reload nginx

- name: Delete backup
Expand Down

0 comments on commit 6fa94f4

Please sign in to comment.