# Variable in templatename ?

**URL:** <https://forum.ansible.com/t/variable-in-templatename/11659>\
**Category:** Ansible Project\
**Created:** [July 9, 2012, 8:06pm UTC](https://forum.ansible.com/t/variable-in-templatename/11659 "2012-07-09T20:06:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ansibleguest](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@ansibleguest](https://forum.ansible.com/u/ansibleguest)\
**Post date:** [July 9, 2012, 8:06pm UTC](https://forum.ansible.com/t/variable-in-templatename/11659/1 "2012-07-09T20:06:00Z")

</div>

Parts of a template filename is not replaced by the variable:

- action: template src=templates/$product\_settings.j2 dest=  
$reg\_settings\_data

fatal: [10.101.1.147] =\> {'msg': "[Errno 2] No such file or directory:  
u'templates/$product\_settings.j2'", 'failed': True}

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [July 9, 2012, 8:13pm UTC](https://forum.ansible.com/t/variable-in-templatename/11659/2 "2012-07-09T20:13:18Z")

</div>

Hi,

Sorry, can’t help you with this unless we see enough of the playbook and enough of the inventory file to see where this is being set.

There are no known issues with basic variable substitution.

---

<div class="post-metadata">

**Author:** ![ansibleguest](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@ansibleguest](https://forum.ansible.com/u/ansibleguest)\
**Post date:** [July 9, 2012, 8:22pm UTC](https://forum.ansible.com/t/variable-in-templatename/11659/3 "2012-07-09T20:22:44Z")

</div>

The Var is just set before:  
vars:  
&nbsp;&nbsp;product: myproduct

Problem is the template filename really is only a part:  
$product\_settings.j2  
to:  
myproduct\_settings.j2

Similar thing is with an include statement using the var within the  
filename:  
# config  
- include: tasks/$product.yml

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [July 9, 2012, 8:24pm UTC](https://forum.ansible.com/t/variable-in-templatename/11659/4 "2012-07-09T20:24:58Z")

</div>

You need to do this then, since it is part of another string:

${product}\_settings.j2 … OR (jinja2 syntax)

{{ product }}\_settings.j2

---

<div class="post-metadata">

**Author:** ![ansibleguest](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@ansibleguest](https://forum.ansible.com/u/ansibleguest)\
**Post date:** [July 9, 2012, 8:35pm UTC](https://forum.ansible.com/t/variable-in-templatename/11659/5 "2012-07-09T20:35:52Z")

</div>

Yes, that ${product}\_settings.j2 works with the template

Thanks !
