mirror of
https://github.com/ansible/ansible-documentation.git
synced 2026-03-27 13:28:51 +07:00
* add conditional
Also backup_file would not be present if updated is not changed
* clarify docs too
* better desc
(cherry picked from commit ba398559c0)
Co-authored-by: Brian Coca <bcoca@users.noreply.github.com>
This commit is contained in:
@@ -18,7 +18,7 @@ Common
|
||||
|
||||
backup_file
|
||||
```````````
|
||||
For those modules that implement `backup=no|yes` when manipulating files, a path to the backup file created.
|
||||
For those modules that implement `backup=no|yes` when manipulating files, a path to the backup file created if original file was changed.
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
|
||||
@@ -826,11 +826,11 @@ and backups, which most file based modules also support:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
- name: update config and backout if validation fails
|
||||
- name: maintain config and backout if validation after change fails
|
||||
block:
|
||||
- name: do the actual update, works with copy, lineinfile and any action that allows for `backup`.
|
||||
template: src=template.j2 dest=/x/y/z backup=yes moreoptions=stuff
|
||||
register: updated
|
||||
- name: do the actual update, works with copy, lineinfile and any action that allows for `backup`.
|
||||
template: src=template.j2 dest=/x/y/z backup=yes moreoptions=stuff
|
||||
register: updated
|
||||
|
||||
- name: run validation, this will change a lot as needed. We assume it returns an error when not passing, use `failed_when` if otherwise.
|
||||
shell: run_validation_commmand
|
||||
@@ -838,17 +838,20 @@ and backups, which most file based modules also support:
|
||||
become_user: requiredbyapp
|
||||
environment:
|
||||
WEIRD_REQUIREMENT: 1
|
||||
when: updated is changed
|
||||
rescue:
|
||||
- name: restore backup file to original, in the hope the previous configuration was working.
|
||||
copy:
|
||||
remote_src: true
|
||||
dest: /x/y/z
|
||||
src: "{{ updated['backup_file'] }}"
|
||||
when: updated is changed
|
||||
always:
|
||||
- name: We choose to always delete backup, but could copy or move, or only delete in rescue.
|
||||
file:
|
||||
path: "{{ updated['backup_file'] }}"
|
||||
state: absent
|
||||
when: updated is changed
|
||||
|
||||
.. _jinja2_faqs:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user