Rule to enforce idempotency of tasks #3058
-
|
ansible-lint already has Confusion over the use of For example, here's a problematic task that sets the system hostname on Ubuntu systems: - name: Set hostname
become: true
ansible.builtin.command: "hostnamectl set-hostname {{ system_hostname }}"
changed_when: trueBy adding - name: Get hostname
ansible.builtin.command: "hostname"
changed_when: false
register: hostname
- name: Set hostname
become: true
ansible.builtin.command: "hostnamectl set-hostname {{ system_hostname }}"
when: hostname.stdout != system_hostnameThis is a trivial example, but there are plenty of cases where one wants to avoid running a potentially large and system-changing operations if they aren't necessary. As |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
To be honest this can be achieved with: I am not sure if we can make a rule for it. What would be needed, to require both |
Beta Was this translation helpful? Give feedback.
To be honest this can be achieved with:
I am not sure if we can make a rule for it. What would be needed, to require both
whenandchanged_whento be present? If so, we still have the problem of conditions from upper block levels, which currently are not accessible tomatchtask().