Kevin C
Kevin C

Reputation: 5720

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.

Upvotes: 12

Views: 28981

Answers (2)

Anurag Singh
Anurag Singh

Reputation: 3

You can also try with ignore_errors.

- name: This task sometimes fail & igonre that tasks and execute next task

  shell: fail_me!

  ignore_errors: true

Upvotes: -4

techraf
techraf

Reputation: 68459

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"

Upvotes: 26

Related Questions