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

Gle*_*eeb 10 linux ansible

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

我只看到一种方法来失败配置fail_when,我想知道是否有任何方法来执行oposite.

看起来像这样的东西:

- name: ping pong redis
  command: redis-cli ping
  register: command_result
  success_when: "'PONG' in command_result.stderr"
Run Code Online (Sandbox Code Playgroud)

谢谢.

Pro*_*e85 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"
Run Code Online (Sandbox Code Playgroud)

如果返回代码为0并且stderr中没有"PONG",则不会失败.因此,如果任何列表是通过它False

  • 值得注意的是,您也可以始终将任何布尔表达式包装在parens中,并在其前面添加"not"以获得相同的效果.例如,`not(url | matches('http://example.com/.*'))`.指出这一点,因为它有点隐藏在这里,因为你使用内联`不在'和`!=`,而一般没有特殊的内联运算符. (4认同)

小智 6

我想也许断言模块就是你想要的.

版本1.5中的新功能

例子:

- assert: { that: "ansible_os_family != 'RedHat'" }
Run Code Online (Sandbox Code Playgroud)