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

Le lundi 13 juin 2016 15:19:36 UTC+2, plat00n a écrit : 

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
> ```
> ---
>
> - 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
>
> ```
> - 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
>
> ```
> - 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
>
> ```
> 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) :
> ```
> #  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
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/4624a0c9-07c8-445c-ae1e-422bd6bebe7f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to