Ansible shell模块不识别“;“失败”;失败任务的属性
以下代码结果Ansible shell模块不识别“;“失败”;失败任务的属性,ansible,Ansible,以下代码结果“dict对象”没有属性“failed”错误: 外壳模块: 结果: fatal: [localhost]: FAILED! => { "failed": true, "msg": "The conditional check 'module_result.failed == false' failed. The error was: error while evaluating conditional (module_result.failed == false): 'dic
“dict对象”没有属性“failed”
错误:
外壳模块:
结果:
fatal: [localhost]: FAILED! => {
"failed": true,
"msg": "The conditional check 'module_result.failed == false' failed. The error was: error while evaluating conditional (module_result.failed == false): 'dict object' has no attribute 'failed'"
}
但是当我将的语法更改为
时:
until: module_result.stderr == ""
它成功地重试。我用-vvv
选项执行调试;重试2次后,按预期失败:
fatal: [localhost]: FAILED! => {
"attempts": 2,
"changed": true,
"cmd": "not_available_command",
"delta": "0:00:00.010290",
"end": "2017-09-25 17:28:14.078318",
"failed": true,
"invocation": {
"module_args": {
"_raw_params": "not_available_command",
"_uses_shell": true,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"warn": true
}
},
"rc": 127,
"start": "2017-09-25 17:28:14.068028",
"stderr": "/bin/sh: 1: not_available_command: not found",
"stderr_lines": [
"/bin/sh: 1: not_available_command: not found"
],
"stdout": "",
"stdout_lines": []
}
如图所示,failed
或stderr
属性都存在,但是在尝试定义语法之前,无法识别failed
让我们尝试使用不同的模块:
获取url模块:
这一次直到:module_result.failed==false
语法起作用<代码>“失败”
属性已识别
那么如何在模块上识别这个问题呢?它似乎是一个错误吗?是的,它似乎是一个错误或非预期行为:
失败
字段在中间尝试期间未填充。您可以使用ANSIBLE\u DEBUG=1检查它:
{
"changed": true,
"end": "2017-09-25 13:01:17.269225",
"stdout": "",
"cmd": "not_available_command",
"rc": 127,
"start": "2017-09-25 13:01:17.257604",
"stderr": "/bin/sh: not_available_command: command not found",
"delta": "0:00:00.011621",
"invocation": {
"module_args": {
"warn": true,
"executable": null,
"_uses_shell": true,
"_raw_params": "not_available_command",
"removes": null,
"creates": null,
"chdir": null
}
},
"warnings": []
}
在Ansible 2.4中,存在失败
字段
有关您的信息,请参阅失败
/成功
您可以在的when/until
语句中使用它们:
until: module_result | succeeded
这在2.2.x和2.3.x中运行良好。您使用什么Ansible版本?这种行为在我的主机上不可复制。我使用ansible 2.3.0.0
{
"changed": true,
"end": "2017-09-25 13:01:17.269225",
"stdout": "",
"cmd": "not_available_command",
"rc": 127,
"start": "2017-09-25 13:01:17.257604",
"stderr": "/bin/sh: not_available_command: command not found",
"delta": "0:00:00.011621",
"invocation": {
"module_args": {
"warn": true,
"executable": null,
"_uses_shell": true,
"_raw_params": "not_available_command",
"removes": null,
"creates": null,
"chdir": null
}
},
"warnings": []
}
until: module_result | succeeded