Ansible-忽略错误时间 [英] Ansible - ignore_errors WHEN
本文介绍了Ansible-忽略错误时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Ansible 2.0.4.0
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": ""}
如果错误输出中出现Errno 32
,是否可以忽略该错误.
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.
推荐答案
您可以使用 failed_when
控制任务何时在Ansible中失败,但是您不能使用
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"
这篇关于Ansible-忽略错误时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文