# How to control \`ignore\_errors\` with a variable

**URL:** <https://forum.ansible.com/t/how-to-control-ignore-errors-with-a-variable/25894>\
**Category:** Ansible Project\
**Created:** [November 2, 2017, 6:25am UTC](https://forum.ansible.com/t/how-to-control-ignore-errors-with-a-variable/25894 "2017-11-02T06:25:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gunther\_Grill](https://avatars.discourse-cdn.com/v4/letter/g/3da27b/32.png) [@Gunther\_Grill](https://forum.ansible.com/u/Gunther_Grill)\
**Post date:** [November 2, 2017, 6:25am UTC](https://forum.ansible.com/t/how-to-control-ignore-errors-with-a-variable/25894/1 "2017-11-02T06:25:50Z")

</div>

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](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)

`

```auto
- 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

`

```auto
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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [November 3, 2017, 2:48am UTC](https://forum.ansible.com/t/how-to-control-ignore-errors-with-a-variable/25894/2 "2017-11-03T02:48:09Z")

</div>

It works for me, using this play:

- hosts: localhost  
gather\_facts: false  
vars:  
&nbsp;&nbsp;&nbsp;ignore: false  
tasks:  
&nbsp;&nbsp;&nbsp;- name: with var  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;assert:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;that:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- item \< 2  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ignore\_errors: '{{ignore|bool}}'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_items: [1,2,3]

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

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

---

<div class="post-metadata">

**Author:** ![Gunther\_Grill](https://avatars.discourse-cdn.com/v4/letter/g/3da27b/32.png) [@Gunther\_Grill](https://forum.ansible.com/u/Gunther_Grill)\
**Post date:** [November 3, 2017, 6:53am UTC](https://forum.ansible.com/t/how-to-control-ignore-errors-with-a-variable/25894/3 "2017-11-03T06:53:15Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [November 3, 2017, 12:33pm UTC](https://forum.ansible.com/t/how-to-control-ignore-errors-with-a-variable/25894/4 "2017-11-03T12:33:47Z")

</div>

that is exactly what should happen, im not sure what you are expecting.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [November 3, 2017, 1:20pm UTC](https://forum.ansible.com/t/how-to-control-ignore-errors-with-a-variable/25894/5 "2017-11-03T13:20:14Z")

</div>

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.
