include_vars in roles not working

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:

Have you gathered facts?

Yes Michael, the play starts by gathering facts. Here:

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

So Michael, any ideas why my playbook fails? As I mentioned, I am gathering facts.

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

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”.

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:

Hi Michael,

Yep, I can replicate this.

Oh, good :slight_smile:

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

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.

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 :frowning:

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

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

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.

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!

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

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

Yeah, this is just because lookup plugins for roles dig inside of ‘files’.

– Michael