clarify backup_file (#1391)

* add conditional

Also backup_file would not be present if updated is not changed

* clarify docs too

* better desc
This commit is contained in:
Brian Coca
2024-05-09 15:48:38 -04:00
committed by GitHub
parent 757b8943fc
commit ba398559c0
2 changed files with 8 additions and 5 deletions

View File

@@ -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

View File

@@ -845,11 +845,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
@@ -857,17 +857,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: