# Conditional check failed

**URL:** <https://forum.ansible.com/t/conditional-check-failed/21749>\
**Category:** Ansible Project\
**Created:** [June 13, 2016, 7:49am UTC](https://forum.ansible.com/t/conditional-check-failed/21749 "2016-06-13T07:49:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![plat00n](https://avatars.discourse-cdn.com/v4/letter/p/6a8cbe/32.png) [@plat00n](https://forum.ansible.com/u/plat00n)\
**Post date:** [June 13, 2016, 7:49am UTC](https://forum.ansible.com/t/conditional-check-failed/21749/1 "2016-06-13T07:49:47Z")

</div>

Hello,

I’m posting here because bcoca told me do that ! ( I have already opened a ticket but bcoca has closed it [\>\> LINK HERE \<\< )](https://github.com/ansible/ansible/issues/16229)

I hope someone will help me 🙂 Thanks

##### ANSIBLE VERSION

ansible 2.1.0.0

##### OS / ENVIRONMENT

CentOS Linux release 7.2.1511 (Core)

##### SUMMARY

My roles don’t work in 2.1.0.0 but in 1.9 it was ok

##### STEPS TO REPRODUCE

for exemple : create one role (my own mysql in the exemple)

set (only one) variable on the invfile (the inventory file) :  
role\_mysql\_version=5.7  
OR  
role\_mysql\_version=5.7

Create 3 files on the tasks folder

main.yml

```auto
---

- name: INCLUDE TASKS for MYSQL 5.6
include: mysql_5.6_OFF.CentOS6.tasks.yml
when: role_mysql_version == "5.6" and "{{ ansible_distribution }}{{ ansible_distribution_version.split('.')[0] }}" == "CentOS6"
tags: tag_role_mysql

- name: INCLUDE TASKS for MYSQL 5.7
include: mysql_5.7_OFF.CentOS7.tasks.yml
when: role_mysql_version == "5.7" and "{{ ansible_distribution }}{{ ansible_distribution_major_version }}" == "CentOS7"
tags: tag_role_mysql

- name: TEST CONCATENATE (for test)
shell: i=`echo {{ ansible_distribution }}{{ ansible_distribution_major_version }}`; echo $i
register: os_vers
tags: tag_role_mysql

- name: INCLUDE TASKS for MYSQL 5.7 (test)
include: mysql_5.7_OFF.CentOS7.tasks.yml
when: role_mysql_version == '5.7' and {{ os_vers.stdout }} == 'CentOS7'
tags: tag_role_mysql

```

mysql\_5.6\_OFF.CentOS6.tasks.yml

```auto
- name: COPY multiples confs as a previous conf (dated)
become: yes
shell: if (/usr/bin/test -e {{ item }}); then cp {{ item }} {{ item }}.`date +%Y%m%d`-`date +%H%M` ;fi
with_items:
- /etc/my.cnf
- /var/lib/mysql/my.cnf
- /var/lib/mysql/.bashrc
- /var/lib/mysql/.bash_profile

```

mysql\_5.7\_OFF.CentOS7.tasks.yml

```auto
- name: COPY multiples confs as a previous conf (dated)
become: yes
shell: if (/usr/bin/test -e {{ item }}); then cp {{ item }} {{ item }}.`date +%Y%m%d`-`date +%H%M` ;fi
with_items:
- /etc/my.cnf
- /var/lib/mysql/my.cnf
- /var/lib/mysql/.bashrc
- /var/lib/mysql/.bash_profile

```

Launch : ansible-playbook -i invfile role.yml -vvvv

##### EXPECTED RESULTS

Include file and play tasks from the included file

##### ACTUAL RESULTS

```auto
TASK [mysql : INCLUDE TASKS for MYSQL 5.6] *************************************
task path: /projet/data/myuser/ansible/roles/mysql/tasks/main.yml:3
skipping: [d1cedtest404] => {"changed": false, "skip_reason": "Conditional check failed", "skipped": true}

TASK [mysql : TEST CONCATENATE] ************************************************
task path: /projet/data/myuser/ansible/roles/mysql/tasks/main.yml:13
changed: [d1cedtest404] => {"changed": true, "cmd": "i=`echo CentOS7`; echo $i", "delta": "0:00:00.002989", "end": "2016-06-10 17:38:59.395801", "rc": 0, "start": "2016-06-10 17:38:59.392812", "stderr": "", "stdout": "CentOS7", "stdout_lines": ["CentOS7"], "warnings": []}

TASK [mysql : INCLUDE TASKS for MYSQL 5.7] *************************************
task path: /projet/data/myuser/ansible/roles/mysql/tasks/main.yml:18
skipping: [d1cedtest404] => {"changed": false, "skip_reason": "Conditional check failed", "skipped": true}

```

This lines were working on 1.9 , in 2.1.0 it’s skipped 😕 If you try to display :  
{{ ansible\_distribution }}{{ ansible\_distribution\_major\_version }}  
“{{ ansible\_distribution }}{{ ansible\_distribution\_version.split(‘.’)[0] }}”  
role\_mysql\_version

This will return the correct value (for the conditionnals)

I tried this (unsuccesfully) :

```auto
# when: role_mysql_version == 5.7 and
# when: ( role_mysql_version == 5.7 ) and ( ansible_distribution ~ ansible_distribution_major_version == CentOS7 )
# when: ( ansible_distribution ~ ansible_distribution_major_version == CentOS7 )
# when: role_mysql_version == "5.7" and "{{ ansible_distribution }}{{ ansible_distribution_major_version }}" == "CentOS7"
# when: role_mysql_version == 5.7 and {{ os_vers.stdout }} == CentOS7

```

Any idea ?

Thanks

---

<div class="post-metadata">

**Author:** ![plat00n](https://avatars.discourse-cdn.com/v4/letter/p/6a8cbe/32.png) [@plat00n](https://forum.ansible.com/u/plat00n)\
**Post date:** [June 13, 2016, 3:00pm UTC](https://forum.ansible.com/t/conditional-check-failed/21749/2 "2016-06-13T15:00:41Z")

</div>

Hello,

SOLUTION FOUND =\>

For information :

in ver 1.9 , variables could be wrote in the inventory file like this : role\_mysql\_version=5.7  
in ver 2.0 , variables must be writed like this : role\_mysql\_version=“5.7”

BR

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 13, 2016, 3:06pm UTC](https://forum.ansible.com/t/conditional-check-failed/21749/3 "2016-06-13T15:06:42Z")

</div>

also your when: clauses are using unnecessary mustaches, which makes them subject to double interpolation bugs.

when: role\_mysql\_version == “5.6” and ansible\_distribution == “CentoOS” and ansible\_distribution\_version.split(‘.’)[0] == 6

or more readable:

when:

- role\_mysql\_version == “5.6”
- ansible\_distribution == “CentoOS”
- ansible\_distribution\_major\_version == “6”
