ansible / proposals

Repository for sharing and tracking progress on enhancement proposals for Ansible.
Creative Commons Zero v1.0 Universal
92 stars 19 forks source link

Add `updates`-clause to `command` and `shell` module #193

Open UnitedMarsupials opened 3 years ago

UnitedMarsupials commented 3 years ago

Add updates clause to command and shell modules

Author: United Marsupials <@UnitedMarsupials>

Date: 20210-05-15

Motivation

Make command and shell modules more useful

Problems

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:

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.