Following this answer, I want to make a copy of OpenSSL's configuration, with a specific set of changes. The original file is out of my control, so I can't make it a template.
At the moment I have:
- name: Make a copy
copy:
src: original.cnf
dest: copy.cnf
force: no
- name: Modify
ini_file:
path: copy.cnf
section: ...
option: ...
value: ...
This sequence of changes is idempotent, but if the original file changes, the change won't be propagated to the copy. If I change this to force: yes
, then original changes will be propagated, but the changes will be performed every time the playbook is run. This is problematic, since I need to restart dependent services in the case of changes, but obviously this must not happen every time.
Is there a way to maintain a copy in such a way that the target file is modified if and only if it's needed?
Based on John's answer, I ended up with the following playbook fragment. The important part is
changed_when: False
, which makes sure that only the step that modifies the target config file copy is counted as a change.