Ansible ignoring Ubuntu yml file

96 views
Skip to first unread message

Vikas Kumar

unread,
Oct 29, 2014, 10:49:33 AM10/29/14
to ansible...@googlegroups.com
Hello Everyone,

I am new to Ansible world. I am just trying to create a small playbook to install apache2 on Debian 7.4 and Ubuntu14.04 servers. 
I have defined few variables in two different yml files - Ubuntu.yml and Debian.yml

My problem is that ansible is ignoring everything is Ubuntu.yml and keep reading variables from Debian.yml. I commented out everything in Ubuntu.yml, still my playbook ran fine as Ansible took values from Debian.yml.

This is a part of my playbook.
- include: Ubuntu.yml
 
when: ansible_os_family == "Debian" and ansible_distribution == "Ubuntu"


- include: Debian.yml
 
when: ansible_os_family == "Debian" and ansible_distribution == "Debian"


Am I missing anything ?

Regards,
Vikas

Michael DeHaan

unread,
Oct 30, 2014, 4:43:17 PM10/30/14
to ansible...@googlegroups.com
This statement will always be False, I think you want "or":

ansible_os_family == "Debian" and ansible_distribution == "Ubuntu"


--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/b09f67a0-0381-4bd2-b26a-e0dc48e266dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vikas Kumar

unread,
Oct 31, 2014, 1:20:56 AM10/31/14
to ansible...@googlegroups.com
Hi Michael,

I am not sure how would "or" work (though I have tried and it doesn't) over here. Generally, statement is true in 'and' clause when both the conditions are true, which are true in this case.

root@ansible:~# ansible box92.test.com -m setup | egrep -w 'ansible_os_family|ansible_distribution'
       
"ansible_distribution": "Ubuntu",
       
"ansible_os_family": "Debian",
root@ansible
:~#
root@ansible
:~# ansible box93.test.com -m setup | egrep -w 'ansible_os_family|ansible_distribution'
       
"ansible_distribution": "Debian",
       
"ansible_os_family": "Debian",
root@ansible
:~#



I have two Debian based distros - Ubuntu 14.04 and Debian 7.40

Ideally, 

- include: Ubuntu.yml
  
when: ansible_os_family == "Debian" and ansible_distribution == "Ubuntu"    (Should pick up vars/Ubuntu.yml)

- include: Debian.yml
  
when: ansible_os_family == "Debian" and ansible_distribution == "Debian"    (Should pick up vars/Debian.yml)

I even tried this, but still Ansible pick up variables defined in vars/Debian.yml :(

- include: Ubuntu.yml
 
when: ansible_distribution == "Ubuntu"

- include: Debian.yml
 
when: ansible_distribution == "Debian"

Or is it ansible only works with 'ansible_os_family' fact.

Is there an alternative to do this ?


Regards,
Vikas

Vikas Kumar

unread,
Oct 31, 2014, 2:25:33 AM10/31/14
to ansible...@googlegroups.com
Hi Michael,

Thanks for your time on this. I got what I was missing. I was including the variable file with ansible_os_family, I should have used ansible_distribution instead. My bad.

This worked like a charm.

include_vars: "{{ ansible_distribution }}.yml"



Regards,
Vikas
Reply all
Reply to author
Forward
0 new messages