include_vars in roles not working

1,297 views
Skip to first unread message

Anand Buddhdev

unread,
Nov 28, 2013, 10:44:25 AM11/28/13
to ansible...@googlegroups.com
Hi people,

I'm on ansible 1.4.1, and trying to use include_vars: for a role called "firewall". I have:

firewall/tasks/main.yml, which starts with:

---

- include_vars: '{{item}}'

  with_first_found:

    - "{{ansible_hostname}}.yml"

    - default.yml

Then I have firewall/vars/default.yml and firewall/vars/HOSTNAME.yml, where HOSTNAME is my hostname.

However, when I include this role in a playbook and run it, I get:

PLAY [localhost] ************************************************************** 

GATHERING FACTS *************************************************************** 

ok: [localhost]

TASK: [firewall | include_vars ] ********************************************** 

fatal: [localhost] => input file not found at /Users/anandb/git/gii-ansible/playbooks/roles/firewall/vars/None or /Users/anandb/git/gii-ansible/playbooks/None

FATAL: all hosts have already failed -- aborting


Any idea what is happening here?

Michael DeHaan

unread,
Nov 28, 2013, 3:27:01 PM11/28/13
to ansible...@googlegroups.com
Have you gathered facts?



--
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.
For more options, visit https://groups.google.com/groups/opt_out.



--
Michael DeHaan <mic...@ansibleworks.com>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

Anand Buddhdev

unread,
Nov 28, 2013, 3:56:55 PM11/28/13
to ansible...@googlegroups.com
Yes Michael, the play starts by gathering facts. Here:

Anand Buddhdev

unread,
Nov 29, 2013, 11:28:35 AM11/29/13
to ansible...@googlegroups.com
So Michael, any ideas why my playbook fails? As I mentioned, I *am* gathering facts.

Gonzalo Servat

unread,
Nov 29, 2013, 7:16:15 PM11/29/13
to ansible-project
If you run the setup module on localhost, is 'ansible_hostname' correctly filled in?


--

Anand Buddhdev

unread,
Nov 30, 2013, 5:50:22 AM11/30/13
to ansible...@googlegroups.com
On Saturday, 30 November 2013 01:16:15 UTC+1, Gonzalo Servat wrote:

Hi Gonzalo,

If you run the setup module on localhost, is 'ansible_hostname' correctly filled in?

Yes, it is:

$ ansible localhost -m setup | grep ansible_hostname

        "ansible_hostname": "clabbers",

My laptop is called "clabbers".

Michael DeHaan

unread,
Nov 30, 2013, 7:54:40 AM11/30/13
to ansible...@googlegroups.com
Yep, I can replicate this.

include_vars is new for 1.4.X so we probably missed a possible use case that someone would want to try.

Please file a github ticket.

Meanwhile, you can work around this in a play like so:

- hosts: webservers
  vars_files: 
      - [ "{{ ansible_hostname }}.yml", "defaults.yml" ]  
  roles:
      - ...

This needs to be set at play level rather than role level, but is basically the original facility ansible had for doing this.


--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Anand Buddhdev

unread,
Nov 30, 2013, 8:19:51 AM11/30/13
to ansible...@googlegroups.com
On Saturday, 30 November 2013 13:54:40 UTC+1, Michael DeHaan wrote:

Hi Michael,

Yep, I can replicate this.

Oh, good :)
 
include_vars is new for 1.4.X so we probably missed a possible use case that someone would want to try.

Please file a github ticket.

Filed as issue #5108
 
Meanwhile, you can work around this in a play like so:

I don't need the work-around urgently, because we're using top-level host_vars and group_vars. When you've fixed this bug, then I will rewrite our playbooks and move those vars files directly into roles. Do you think you will make a 1.4.2 release for this? In that case, I'm happy to just wait a few days for it.

Regards,

Anand 

Michael DeHaan

unread,
Dec 1, 2013, 8:55:15 AM12/1/13
to ansible...@googlegroups.com
This generally isn't something we'd force a dot release for, unless we otherwise thought we needed to cut a dot release.

If we did, we'd likely wait longer as well.






--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Anand Buddhdev

unread,
Dec 1, 2013, 9:11:48 AM12/1/13
to ansible...@googlegroups.com, ansible...@googlegroups.com
That's a bummer because I was waiting to make use of this feature in 1.4. If I have to wait for 1.5 then I'm stuck using top-level host_vars and group_vars :(

Why would you not make a point release for this if it's a bug? My example is written exactly as you described in a message several days ago when introducing this feature and your own example is actually failing for me.

Anand
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/UQ_ArPEofFU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.

Matt Coddington

unread,
Dec 1, 2013, 9:19:30 AM12/1/13
to ansible...@googlegroups.com
i believe i had run into something very similar, if not identical, trying to follow Michael's original post on this.  my solution ended up being to reference the vars dir relatively as opposed to assuming ansible could just find it; my bad for not submitting a bug.  Anand, does something like this work for you?

- include_vars: "{{ item }}"
  with_first_found:
    - ../vars/{{ ansible_hostname }}.yml
    - ../vars/default.yml

Michael DeHaan

unread,
Dec 1, 2013, 9:51:20 AM12/1/13
to ansible...@googlegroups.com
Please take time to re-read the email, and then perhaps read this fine piece of literature:  http://en.wikipedia.org/wiki/The_Little_Red_Hen

I didn't say we weren't going to do a point release.

The original poster requested that we do a point release for him in a few days.   I don't see a reason to pick that particular bug to immediately cut a point release when we've released one very recently.

I didn't rule out future point releases.

This is a new module, completely new in this release, so it's a bit less severe than if we broke a released feature. You have a reasonable workaround for the interim.




Michael DeHaan

unread,
Dec 1, 2013, 9:56:14 AM12/1/13
to ansible...@googlegroups.com
Ah yeah, this much is true, because the native search path for roles files is in "./files".

This is actually the way lookup plugins work, and it's fine.

I had inadvertedly done my non-roles testing without naming the filename correctly so this is working for me too.

Good, not a bug!


Anand Buddhdev

unread,
Dec 1, 2013, 11:38:28 AM12/1/13
to ansible...@googlegroups.com
On Sunday, 1 December 2013 15:19:30 UTC+1, Matt Coddington wrote:

Hi Matt,

i believe i had run into something very similar, if not identical, trying to follow Michael's original post on this.  my solution ended up being to reference the vars dir relatively as opposed to assuming ansible could just find it; my bad for not submitting a bug.  Anand, does something like this work for you?

- include_vars: "{{ item }}"
  with_first_found:
    - ../vars/{{ ansible_hostname }}.yml
    - ../vars/default.yml

Yes, this does work. Thank you for suggesting it.

Regards,

Anand 

Anand Buddhdev

unread,
Dec 1, 2013, 11:44:34 AM12/1/13
to ansible...@googlegroups.com
On Sunday, 1 December 2013 15:56:14 UTC+1, Michael DeHaan wrote:

Hi Michael,
Ah yeah, this much is true, because the native search path for roles files is in "./files".

This is actually the way lookup plugins work, and it's fine.

I had inadvertedly done my non-roles testing without naming the filename correctly so this is working for me too.

Good, not a bug!

Thank you for the lesson about the Litte Red Hen.

So if I understand this correctly, there's no bug to fix, and I have to use ../vars/filename with lookup plugins?

Regards,

Anand 

Michael DeHaan

unread,
Dec 1, 2013, 12:51:55 PM12/1/13
to ansible...@googlegroups.com
Yeah, this is just because lookup plugins for roles dig inside of 'files'.

-- Michael
--
Reply all
Reply to author
Forward
0 new messages