【问题标题】:Using ansible ignore_errors in a loop在循环中使用 ansible ignore_errors
【发布时间】:2017-10-16 19:58:57
【问题描述】:

我正在使用 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,它也可以工作 - 但这没有任何意义,不是吗。

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

【问题讨论】:

  • 我不一定相信fail 模块的行为方式与另一个动作模块失败的方式相同。你的目标是什么?您想要一个通用的答案/解决方案,或者专门针对fail

标签: ansible ansible-2.x


【解决方案1】:

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

【讨论】:

  • 感谢您调查并提交问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-11-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多