# include\_vars in roles not working

**URL:** <https://forum.ansible.com/t/include-vars-in-roles-not-working/14025>\
**Category:** Ansible Project\
**Created:** [November 28, 2013, 3:44pm UTC](https://forum.ansible.com/t/include-vars-in-roles-not-working/14025 "2013-11-28T15:44:25Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anand\_Buddhdev2](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@Anand\_Buddhdev2](https://forum.ansible.com/u/Anand_Buddhdev2)\
**Post date:** [November 28, 2013, 3:44pm UTC](https://forum.ansible.com/t/include-vars-in-roles-not-working/14025/1 "2013-11-28T15:44:25Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [November 28, 2013, 8:27pm UTC](https://forum.ansible.com/t/include-vars-in-roles-not-working/14025/2 "2013-11-28T20:27:01Z")

</div>

Have you gathered facts?

---

<div class="post-metadata">

**Author:** ![Anand\_Buddhdev2](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@Anand\_Buddhdev2](https://forum.ansible.com/u/Anand_Buddhdev2)\
**Post date:** [November 28, 2013, 8:56pm UTC](https://forum.ansible.com/t/include-vars-in-roles-not-working/14025/3 "2013-11-28T20:56:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Anand\_Buddhdev2](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@Anand\_Buddhdev2](https://forum.ansible.com/u/Anand_Buddhdev2)\
**Post date:** [November 29, 2013, 4:28pm UTC](https://forum.ansible.com/t/include-vars-in-roles-not-working/14025/4 "2013-11-29T16:28:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Gonzalo\_Servat](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Gonzalo\_Servat](https://forum.ansible.com/u/Gonzalo_Servat)\
**Post date:** [November 30, 2013, 12:16am UTC](https://forum.ansible.com/t/include-vars-in-roles-not-working/14025/5 "2013-11-30T00:16:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Anand\_Buddhdev2](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@Anand\_Buddhdev2](https://forum.ansible.com/u/Anand_Buddhdev2)\
**Post date:** [November 30, 2013, 10:50am UTC](https://forum.ansible.com/t/include-vars-in-roles-not-working/14025/6 "2013-11-30T10:50:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [November 30, 2013, 12:54pm UTC](https://forum.ansible.com/t/include-vars-in-roles-not-working/14025/7 "2013-11-30T12:54:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Anand\_Buddhdev2](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@Anand\_Buddhdev2](https://forum.ansible.com/u/Anand_Buddhdev2)\
**Post date:** [November 30, 2013, 1:19pm UTC](https://forum.ansible.com/t/include-vars-in-roles-not-working/14025/8 "2013-11-30T13:19:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [December 1, 2013, 1:55pm UTC](https://forum.ansible.com/t/include-vars-in-roles-not-working/14025/9 "2013-12-01T13:55:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Anand\_Buddhdev2](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@Anand\_Buddhdev2](https://forum.ansible.com/u/Anand_Buddhdev2)\
**Post date:** [December 1, 2013, 2:11pm UTC](https://forum.ansible.com/t/include-vars-in-roles-not-working/14025/10 "2013-12-01T14:11:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Matt\_Coddington](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Matt\_Coddington](https://forum.ansible.com/u/Matt_Coddington)\
**Post date:** [December 1, 2013, 2:19pm UTC](https://forum.ansible.com/t/include-vars-in-roles-not-working/14025/11 "2013-12-01T14:19:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [December 1, 2013, 2:51pm UTC](https://forum.ansible.com/t/include-vars-in-roles-not-working/14025/12 "2013-12-01T14:51:20Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [December 1, 2013, 2:56pm UTC](https://forum.ansible.com/t/include-vars-in-roles-not-working/14025/13 "2013-12-01T14:56:14Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Anand\_Buddhdev2](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@Anand\_Buddhdev2](https://forum.ansible.com/u/Anand_Buddhdev2)\
**Post date:** [December 1, 2013, 4:38pm UTC](https://forum.ansible.com/t/include-vars-in-roles-not-working/14025/14 "2013-12-01T16:38:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Anand\_Buddhdev2](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@Anand\_Buddhdev2](https://forum.ansible.com/u/Anand_Buddhdev2)\
**Post date:** [December 1, 2013, 4:44pm UTC](https://forum.ansible.com/t/include-vars-in-roles-not-working/14025/15 "2013-12-01T16:44:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [December 1, 2013, 5:51pm UTC](https://forum.ansible.com/t/include-vars-in-roles-not-working/14025/16 "2013-12-01T17:51:55Z")

</div>

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

– Michael
