Inconsistency in variable interpretation in ignore_errors when combined with with_items ...

15 views
Skip to first unread message

G Sudduth

unread,
Aug 17, 2017, 2:14:16 PM8/17/17
to Ansible Project
Hi,

So, I have a task  ...

---
- name: FAILER!
  command: /bin/false
  #with_items:
  #  - one
  #  - two
  #ignore_errors: True
  ignore_errors: "{{ ignore_replication_errors | default(false) }}"

If I go ...

ansible-playbook  test.pl --extra-vars "ignore_replication_errors=false"
ansible-playbook  test.pl --extra-vars "ignore_replication_errors=true"

... it works correctly ...

localhost    : ok=5    changed=1    unreachable=0    failed=1 
... and ...
localhost    : ok=5    changed=1    unreachable=0    failed=0

However, if I change it like this ...
---
- name: FAILER!
  command: /bin/false
  with_items:
    - one
    - two
  #ignore_errors: True
  ignore_errors: "{{ ignore_replication_errors | default(false) }}"

... it always ignores ...

localhost    : ok=5    changed=1    unreachable=0    failed=0

Also, it works as expected if I take the variable out and explicitly set True or False ...
---
- name: FAILER!
  command: /bin/false
  with_items:
    - one
    - two
  ignore_errors: True
  #ignore_errors: "{{ ignore_replication_errors | default(false) }}"

So, it kinda feels like the variable interpretation working differently when I throw with_items into the mix. I was thinking that maybe using quotes and squiggly braces was causing the value of the variable to be interpreted as a string instead of a boolean, but after a lot of fiddling with it (using |bool etc.) I couldn't find another syntax that worked.

Is this a bug? Am I missing something?

Thanks, 
--
Glenn

PS 

ansible-playbook --version
ansible-playbook 2.3.1.0
  config file = ...
  configured module search path = Default w/o overrides
  python version = 2.7.13 (default, Jun 26 2017, 10:20:05) [GCC 7.1.1 20170622 (Red Hat 7.1.1-3)]







G Sudduth

unread,
Aug 23, 2017, 12:10:30 PM8/23/17
to Ansible Project
In case someone else hits this fascinating problem. This is what I had to do in the end ...

---
- name: FAILER!
  command: /bin/false
  register: result
  with_items:
    - one
    - two
  ignore_errors: True

- name: Error checker
  fail:
    msg: "FAILER! FAILED!"
  when: result.failed is defined and (ignore_replication_errors is not defined or (ignore_replication_errors is defined and not ignore_replication_errors|bool))
Reply all
Reply to author
Forward
0 new messages