What are `changed_when` and `failed_when` used for?
IntermediateConceptVault, Privilege Escalation and Error Handling
Answer
They override Ansible's own judgement of a task result using conditions on the registered output.
- ansible.builtin.command: /usr/local/bin/rotate-keys
register: rot
changed_when: "'rotated 0' not in rot.stdout"
failed_when:
- rot.rc != 0
- "'already running' not in rot.stderr"
changed_when: false marks read-only commands as not changing anything, which keeps recaps clean and keeps handlers from firing. A list under failed_when is an AND.
More on Vault, Privilege Escalation and Error Handling
What is Ansible Vault?BeginnerWhich `ansible-vault` commands do you use day to day?BeginnerHow do you supply the vault password when running a playbook?BeginnerWhat is `encrypt_string` and when is it better than encrypting a whole file?IntermediateWhat are vault IDs and why use them?AdvancedHow is Vault data encrypted and what does the file look like?Advanced