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”, reponseOK: “UP”, portMS: 8083, delayInit: 10, hostMS: “backend”}
Can you please help me please?
Thank you in advance !