ansible

Ansible - ignore_errors WHEN


Ansible 2.0.4.0

There are about three tasks which randomly fails. The output of the fail is:

OSError: [Errno 32] 
Broken pipefatal: [machine1]: FAILED! => {"failed": true, "msg": "Unexpected failure during module execution.", "stdout": ""}

Is it possible to ignore the error, if Errno 32 is in the output of the error.

- name: This task sometimes fails
  shell: fail_me!
  ignore_errors: "{{ when_errno32 }}"

I"m aware this is a workaround. Solving the 'real' problem could take up way more time.


Solution

  • You can use failed_when to control when a task should fail in Ansible, but you cannot use ignore_errors for a specific return code, it is a simple yes/no switch.

    So in your case you can add an expression:

    - name: This task sometimes fails
      shell: fail_me!
      register: fail_me
      failed_when: "fail_me.rc != 0 and fail_me.rc != 32"