How to control `ignore_errors` with a variable

132 views
Skip to first unread message

guenhter

unread,
Nov 2, 2017, 2:25:50 AM11/2/17
to Ansible Project
Hi,

I already opened an issue for my question but I was advised to come here first.
The detailed description is available under https://github.com/ansible/ansible/issues/32384
To sum it up:

I cannot manage to make the `ignore_errors` work with a variable.
When I use a hardcoded boolean it works, but when I use a boolean variable it always evaluated to true (ignore errors)

- hosts: 127.0.0.1
 
vars:
   
ignore_assertion_errors: false
 
tasks:
   
- name: With variable
     
assert:
       
that: item < 2
       
msg: "{{item}} isn't < 2"
     
ignore_errors: ignore_assertion_errors
     
with_items:
       
- 1
       
- 2

   
- name: With 'false' as hardcoded boolean
     
assert:
       
that: item < 2
       
msg: "{{item}} isn't < 2"
     
ignore_errors: false
     
with_items:
       
- 1
       
- 2

I already tried out the following constructs

ignore_errors: "{{ignore_assertion_errors}}"
ignore_errors
: ignore_assertion_errors
ignore_errors
: "{{ignore_assertion_errors|bool}}"
ignore_errors
: ignore_assertion_errors|bool


But always with the same result: the errors of the first task are always ignored.

Can anybody  explain what I'm doing wrong, because from my current  point of view this is an error.

cheers

Brian Coca

unread,
Nov 2, 2017, 10:48:25 PM11/2/17
to Ansible Project
It works for me, using this play:

- hosts: localhost
gather_facts: false
vars:
ignore: false
tasks:
- name: with var
assert:
that:
- item < 2
ignore_errors: '{{ignore|bool}}'
with_items: [1,2,3]

I get the following output (note the 'ignoring' at the end:

ok: [localhost] => (item=1) => {
"changed": false,
"item": 1,
"msg": "All assertions passed"
}
failed: [localhost] (item=2) => {
"assertion": "item < 2",
"changed": false,
"evaluated_to": false,
"item": 2
}
failed: [localhost] (item=3) => {
"assertion": "item < 2",
"changed": false,
"evaluated_to": false,
"item": 3
}
...ignoring





--
----------
Brian Coca

guenhter

unread,
Nov 3, 2017, 2:53:15 AM11/3/17
to Ansible Project
HI, no, this doesn't work. You see in you output

...ignoring

This means, that the errors are ignored.
Also the PLAY RECAP shows, that everything is ok, and no tasks failed.
If you add another task after the one already contained, it is still executed, but this should no happen...

Brian Coca

unread,
Nov 3, 2017, 8:34:02 AM11/3/17
to Ansible Project
that is exactly what should happen, im not sure what you are expecting.


------------------
Brian Coca

Brian Coca

unread,
Nov 3, 2017, 9:20:32 AM11/3/17
to Ansible Project
sorry, im being stupid here ( thanks Toshio for bringing me to my senses). I write "false" but keep reading True.... 

You are correct, the expression is being incorrectly evaluated, Ill reopen the ticket.
Reply all
Reply to author
Forward
0 new messages