控制对失败的定义
New in version 1.4.
假设一条命令的错误码毫无意义只有它的输出结果能告诉你什么出了问题,比如说字符串 “FAILED” 出 现在输出结果中.
在 Ansible 1.4及之后的版本中提供了如下的方式来指定这样的特殊行为:
- name: this command prints FAILED when it fails command: /usr/bin/example-command -x -y -z
register: command_result
failed_when: "'FAILED' in command_result.stderr"
在 Ansible 1.4 之前的版本能通过如下方式完成:
- name: this command prints FAILED when it fails command: /usr/bin/example-command -x -y -z
register: command_result
ignore_errors: True
- name: fail the play if the previous command did not succeed
fail: msg="the command failed"
when: "'FAILED' in command_result.stderr"
覆写更改结果
New in version 1.3.
When a shell/command or other module runs it will typically report “changed” status based on whether it thinks it affected machine state. 当一个 shell或命令或其他模块运行时,它们往往都会在它们认为其影响机器状态时报告 “changed” 状态