在循环中使用 ansible ignore_errors

Using ansible ignore_errors in a loop

我正在使用 ansible 2.4.0 并尝试根据检查模式使用 ignore_errors 并结合使用 with_items。 根据 docs about check_mode,您可以根据 ansible 是否处于检查模式 运行 来定义 ignore_errors。如果没有 with_items 指令,这很好用,但是对于这两个元素,失败总是被忽略。

没有with_items的工作示例:

# test_i.yml
- name: test without array and with ignore
  hosts: all
  gather_facts: no
  tasks:
    - fail: msg="I fail, but ignored in check mode"
      ignore_errors: "{{ ansible_check_mode }}"

    - debug: msg="Reachable only in check mode"

无效示例:

# test_ai.yml
- name: test with array and with ignore
  hosts: all
  gather_facts: no
  tasks:
    - fail: msg="I am always skipped"
      ignore_errors: "{{ ansible_check_mode }}"
      with_items: [ 1, 2 ]

    - debug: msg="Always reached"

执行结果:

ansible-playbook test_i.yml --check
# ok=2, failed=0, but fail-task printed in red
ansible-playbook test_i.yml
# ok=0, failed=1, canceled after fail task
ansible-playbook test_ai.yml --check
# ok=2, failed=0, but fail-task items printed in red
ansible-playbook test_ai.yml
# ok=2, failed=0, same as with check

如果 ignore_errors 被删除或注释掉,任务会按预期失败,但它也会在检查模式下失败。即使 check_mode 被定义为 false,它也能工作——但这​​没有任何意义,对吧。

我是不是遗漏了什么或者这可能是一个错误?

是的,这是一个错误。我已提交问题 31831 并附有解释。