是否有一些Ansible相当于" failed_when"为了成功

时间:2015-01-06 09:54:29

标签: linux ansible

查看有关错误处理的文档Ansible error handling

我只看到一种方法来使配置失败fail_when,我想知道是否有办法做对话。

看起来像这样的东西:

- name: ping pong redis
  command: redis-cli ping
  register: command_result
  success_when: "'PONG' in command_result.stderr"

感谢。

2 个答案:

答案 0 :(得分:14)

似乎没有这样的功能,至少我在邮件列表上的建议仍未得到回应:

https://groups.google.com/forum/#!topic/ansible-project/cIaQTmY3ZLE

可能有用的是知道failed_when的行为与其语义不同:

- name: ping pong redis
  command: redis-cli ping
  register: command_result
  failed_when: 
    - "'PONG' not in command_result.stderr"
    - "command_result.rc != 0"
如果返回代码为0并且没有' PONG'

失败在stderr。 因此,如果任何列表为False

,则通过

答案 1 :(得分:6)

我想也许assert module就是你想要的。

  

1.5版中的新功能

     

示例:

- assert: { that: "ansible_os_family != 'RedHat'" }
相关问题