# Using variable into failed\_when in a role

**URL:** <https://forum.ansible.com/t/using-variable-into-failed-when-in-a-role/35421>\
**Category:** Ansible Project\
**Created:** [June 28, 2021, 8:50am UTC](https://forum.ansible.com/t/using-variable-into-failed-when-in-a-role/35421 "2021-06-28T08:50:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabriel\_westrelin](https://avatars.discourse-cdn.com/v4/letter/g/9f8e36/32.png) [@gabriel\_westrelin](https://forum.ansible.com/u/gabriel_westrelin)\
**Post date:** [June 28, 2021, 8:50am UTC](https://forum.ansible.com/t/using-variable-into-failed-when-in-a-role/35421/1 "2021-06-28T08:50:02Z")

</div>

In a role, I would like to use a variable that I set when calling in the playbook in a “failed\_when”. I still have this error:

_FAILED! =\> {“msg”: “The conditional check ‘vars.reponseOK not in reponse.content’ failed. The error was: error while evaluating conditional (vars.reponseOK not in reponse.content): Unable to look up a name or access an attribute in template string ({% if vars.reponseOK not in reponse.content %} True {% else %} False {% endif %}).\nMake sure your variable name does not contain invalid characters like ‘-’: argument of type ‘AnsibleUndefined’ is not iterable”}_

I tried a lot of things: put “”, some ', with nothing and nothing helped, I always have the same error.

In the role/tasks/main.yml, I have this :

_- name: “Appel du sanitycheck du MS”_  
_block:_  
_- name: “tentative pour appeller la sanityUrl”_  
_uri:_  
_url: “{{vars.sanityUrl}}”_  
_return\_content: yes_  
_register: reponse_  
_failed\_when: " vars.reponseOK not in reponse.content "_  
_rescue:_  
_- name: "On va attendre que le port soit up… "_  
_wait\_for:_  
_port: “{{vars.portMS|int}}”_  
_delay: “{{vars.delayInit|int}}”_  
_state: started_  
_timeout: 60_  
_- name: “2ième tentative pour appeller la sanityUrl”_  
_uri:_  
_url: “{{vars.sanityUrl}}”_  
_return\_content: yes_  
_register: reponse_  
_failed\_when: " vars.reponseOK not in reponse.content "_

And I call the role in the playbook with this:

_- name: “Check Backend sur les VM backend”_  
_hosts: backend_  
_gather\_facts: False_  
_#any\_errors\_fatal: yes_  
_tasks:_  
_- name: “boucle”_  
_include\_role:_  
_name: “Common/sanitycheckms”_  
_vars:_  
_- sanityUrl: “{{ item.sanityUrl }}”_  
_- portMS: “{{ item.portMS }}”_  
_- delayInit: “{{ item.delayInit }}”_  
_- reponseOK: “{{ item.reponseOK }}”_  
_loop:_  
_- { sanityUrl: “[http://localhost:8083/actuator/health](http://localhost:8083/actuator/health)”, reponseOK: “UP”, portMS: 8083, delayInit: 10, hostMS: “backend”}_

Can you please help me please?

Thank you in advance !

---

<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:** [June 29, 2021, 2:10pm UTC](https://forum.ansible.com/t/using-variable-into-failed-when-in-a-role/35421/2 "2021-06-29T14:10:47Z")

</div>

failed\_when deals with the return status of a task's action, it cannot  
shortcut any syntax or definition errors.
