When a command (or shell) task is meant to modify a file -- in a way, for which no other tasks exist (beyond lineinfile or patch), there are following problems:
A status of the task is always "changed" by default, even when it made no changes.
There is no way to see the "diff" of the modified files -- without implementing multiple tasks for it.
Solution proposal
Similar to the already-present creates clause, the module could have an updates clause, which shall cause Ansible to diff the listed file(s) and to automatically set changed to False, if no changes actually took place.
- name: Run the reports
command: runreports.sh
updates:
- /prod/reports/sales.csv
- /prod/reports/accounting.csv
- name: Dump my table
shell: isql -b > dump.txt
args:
stdin: |-
SELECT * FROM MYTABLE
go
updates: dump.txt
Documentation (optional)
Parameter
Choices/Defaults
Comments
updates (path)
A filename or glob pattern -- or a list of such. The task will be considered unchanged, if none of the listed files are modified. If "diff" is requested, these files will be compared to their older versions.
Add
updates
clause tocommand
andshell
modulesAuthor: United Marsupials <@UnitedMarsupials>
Date: 20210-05-15
Motivation
Make
command
andshell
modules more usefulProblems
When a
command
(orshell
) task is meant to modify a file -- in a way, for which no other tasks exist (beyondlineinfile
orpatch
), there are following problems:Solution proposal
Similar to the already-present
creates
clause, the module could have anupdates
clause, which shall cause Ansible to diff the listed file(s) and to automatically setchanged
toFalse
, if no changes actually took place.Documentation (optional)
updates
(path)