# vars\_files- use of variables in filename

**URL:** <https://forum.ansible.com/t/vars-files-use-of-variables-in-filename/28014>\
**Category:** Ansible Project\
**Created:** [July 10, 2018, 5:11pm UTC](https://forum.ansible.com/t/vars-files-use-of-variables-in-filename/28014 "2018-07-10T17:11:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![smalleni](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@smalleni](https://forum.ansible.com/u/smalleni)\
**Post date:** [July 10, 2018, 5:11pm UTC](https://forum.ansible.com/t/vars-files-use-of-variables-in-filename/28014/1 "2018-07-10T17:11:36Z")

</div>

Hi,

I am including a vars file in my playbook as follows:

vars\_files:

- vars/{{((test|default(‘’)).ansible|default(‘’)).vars|default(‘install.yml’)}}

test.ansible.vars is passed from the cli.

However, I am seeing ansible.errors.AnsibleFileNotFound: vars file vars/{{((test|default(‘’)).ansible|default(‘’)).vars|default(‘install.yml’)}} was not found when running the playbook. Anything I am doing wrong?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 11, 2018, 9:58am UTC](https://forum.ansible.com/t/vars-files-use-of-variables-in-filename/28014/2 "2018-07-11T09:58:29Z")

</div>

To my knowledge vars\_files doesn't support jinja template, you can use the include\_vars instead.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [July 11, 2018, 3:13pm UTC](https://forum.ansible.com/t/vars-files-use-of-variables-in-filename/28014/3 "2018-07-11T15:13:19Z")

</div>

it does support templating, that expression makes no sense to me.

---

<div class="post-metadata">

**Author:** ![Varun\_Chopra](https://avatars.discourse-cdn.com/v4/letter/v/54ee81/32.png) [@Varun\_Chopra](https://forum.ansible.com/u/Varun_Chopra)\
**Post date:** [July 11, 2018, 4:08pm UTC](https://forum.ansible.com/t/vars-files-use-of-variables-in-filename/28014/4 "2018-07-11T16:08:52Z")

</div>

He’s breaking it into pieces and creating defaults lol

- vars/{{ ( (test | default(‘’) ).ansible|default(‘’)).vars | default(‘install.yml’) }}

---

<div class="post-metadata">

**Author:** ![smalleni](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@smalleni](https://forum.ansible.com/u/smalleni)\
**Post date:** [July 11, 2018, 4:21pm UTC](https://forum.ansible.com/t/vars-files-use-of-variables-in-filename/28014/5 "2018-07-11T16:21:45Z")

</div>

@Varun Chopra First of all, I don’t think there is anything to “lol” about here. If you don’t know something you ask. And if you know something you either help the other person understand/stay silent.

The reason I had a default for each level is because there could be cases where test or test.ansible are not defined as indicated in comment here ([https://github.com/ansible/ansible/issues/41507#issuecomment-397069455](https://github.com/ansible/ansible/issues/41507#issuecomment-397069455))

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [July 11, 2018, 4:42pm UTC](https://forum.ansible.com/t/vars-files-use-of-variables-in-filename/28014/6 "2018-07-11T16:42:45Z")

</div>

you realize that '' cannot have .anything? you need default({}) to  
make it a dictionary, which CAN have keys

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 11, 2018, 4:45pm UTC](https://forum.ansible.com/t/vars-files-use-of-variables-in-filename/28014/7 "2018-07-11T16:45:10Z")

</div>

I didn't use a list in vars\_files: so that why it failed for me, with a list I see it support templating.

---

<div class="post-metadata">

**Author:** ![smalleni](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@smalleni](https://forum.ansible.com/u/smalleni)\
**Post date:** [July 11, 2018, 4:46pm UTC](https://forum.ansible.com/t/vars-files-use-of-variables-in-filename/28014/8 "2018-07-11T16:46:45Z")

</div>

Ah makes sense, thanks bcoca!

---

<div class="post-metadata">

**Author:** ![Varun\_Chopra](https://avatars.discourse-cdn.com/v4/letter/v/54ee81/32.png) [@Varun\_Chopra](https://forum.ansible.com/u/Varun_Chopra)\
**Post date:** [July 11, 2018, 7:18pm UTC](https://forum.ansible.com/t/vars-files-use-of-variables-in-filename/28014/9 "2018-07-11T19:18:52Z")

</div>

Did you get offended? I’m sorry. I hope you didn’t burst a vein.
