Ok so I have this code(using version 2.0.1.0 of ansible):
<pre>
---
- hosts: localhost
become: yes
gather_facts: yes
vars:
version: "6.5.5"
vars_files:
- vars/{{ ansible_os_family }}.yml
roles:
- role: ubuntu_packages
tags: ubuntu_packages
when: ansible_os_family == "Debian"
- role: redhat_packages
tags: redhat_packages
when: ansible_os_family == "RedHat"
- role: windows_packages
tags: windows_packages
when: ansible_os_family == "Windows"
</pre>
But when I run it using ansible-playbook foo.yml, Im getting:
<pre>
PLAY ***************************************************************************
TASK [setup] *******************************************************************
ok: [localhost]
TASK [ubuntu_packages : include_vars] ******************************************
ok: [localhost] => (item=/root/scanner/ubuntu_packages/vars/Ubuntu_14.yml)
TASK [ubuntu_packages : Gather_ec2_facts] **************************************
ok: [localhost]
TASK [ubuntu_packages : debug] *************************************************
ok: [localhost] => {
"file_url_full": "VARIABLE IS NOT DEFINED!"
}
TASK [redhat_packages : include_vars] ******************************************
fatal: [localhost]: FAILED! => {"failed": true, "msg": "No file was found when using with_first_found. Use the 'skip: true' option to allow this task to be skipped if no files are found"}
NO MORE HOSTS LEFT *************************************************************
to retry, use: --limit @scanner.retry
PLAY RECAP *********************************************************************
localhost : ok=4 changed=0 unreachable=0 failed=1
</pre>
In other words the "when" statement is simply ignored when chosing the role and it executes the RedHat role right after the Ubuntu role although it shouldn't since ansible_os_family is Debian and if the when statement would work then there should be no error here. Seems like a serious bug in ansible.
Note: Tests are being done on ubuntu 14.04