Reputation: 2098
I'm using ansible 2.4.0 and try to use ignore_errors
depending on check mode and with_items
in combination.
According to the docs about check_mode you can define ignore_errors based on if ansible is running in check mode or not. Without the with_items
directive this works good, but with both elements a fail is always ignored.
Working example without 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"
Not working example:
# 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"
Execute with and results:
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
If the ignore_errors is removed or commented out, the task fails as desired, but then it does in check mode, too. It works even if check_mode
is defined as false - but that wouldn't make any sense, would it.
Am I missing something or might this be a bug?
Upvotes: 2
Views: 4059
Reputation: 68339
Yes, this is a bug. I've filed an issue 31831 with explanation.
Upvotes: 2