私は2.4.0を使用していますが、チェックモードに応じてignore_errors
、組み合わせでwith_items
を使用しようとしています。 docs about check_modeによると、誰かがチェックモードで動作しているかどうかに基づいてignore_errorsを定義することができます。 with_items
指令がなければ、これはうまくいきますが、両方の要素でfailは常に無視されます。例作業ループ内のあるignore_errorsを使用する
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'モジュールが別のアクションモジュールが失敗するのと同じ方法で動作するとは必ずしも信じていません。あなたの目的は何ですか?一般的な回答/解決策が必要な場合や、特に「失敗」の場合 – techraf