Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible - ignore_errors WHEN

Tags:

ansible

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.

like image 796
Kevin C Avatar asked Mar 07 '17 16:03

Kevin C


1 Answers

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"
like image 165
techraf Avatar answered Oct 07 '22 16:10

techraf