# In older versions of ansible use ``success``, now both are valid but succeeded uses the correct tense. -command:/bin/something_else when:resultissucceeded
-name:checkcontentsforemptiness debug: msg:"Directory is empty" when:contents.stdout==""
1 2 3 4 5 6 7 8
- name: test play hosts: mfs tasks: - shell: cat /etc/motd register: motd_contents
- shell: echo "motd contains the word hi" > /tmp/test2 when: motd_contents.stdout.find('hi') != -1
changed_when
1 2 3 4 5 6 7 8
tasks: - shell: /usr/bin/billybass --mode="take me to the river" register: bass_result changed_when: "bass_result.rc != 2" # this will never report 'changed' status - shell: wall 'beep' changed_when: False
failed_when
1 2 3 4
- name: this command prints FAILED when it fails command: /usr/bin/example-command -x -y -z register: command_result failed_when: "'FAILED' in command_result.stderr"
1 2 3 4 5 6 7 8
- name: this command prints FAILED when it fails command: /usr/bin/example-command -x -y -z register: command_result ignore_errors: True
- name: fail the play if the previous command did not succeed fail: msg="the command failed" when: "'FAILED' in command_result.stderr"