Hello,
I’m posting here because bcoca told me do that ! ( I have already opened a ticket but bcoca has closed it >> LINK HERE << )
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