Skip to content

Commit

Permalink
clarify backup_file (#1391) (#1440)
Browse files Browse the repository at this point in the history
* add conditional

Also backup_file would not be present if updated is not changed

* clarify docs too

* better desc

(cherry picked from commit ba39855)

Co-authored-by: Brian Coca <bcoca@users.noreply.github.com>
  • Loading branch information
patchback[bot] and bcoca committed May 9, 2024
1 parent 8025c52 commit 24571d0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions docs/docsite/rst/reference_appendices/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -826,29 +826,32 @@ 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
become: true
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:

Expand Down

0 comments on commit 24571d0

Please sign in to comment.