Ansible - ignore_errors WHEN [英] Ansible - ignore_errors WHEN

查看:24
本文介绍了Ansible - ignore_errors WHEN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 中何时失败,但您不能使用 ignore_errors 对于特定的返回码,它是一个简单的是/否开关.

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 - ignore_errors WHEN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆