# Variable name composition

**URL:** <https://forum.ansible.com/t/variable-name-composition/14274>\
**Category:** Ansible Project\
**Created:** [January 5, 2014, 5:21pm UTC](https://forum.ansible.com/t/variable-name-composition/14274 "2014-01-05T17:21:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Antonio\_Marin\_Cerezu](https://avatars.discourse-cdn.com/v4/letter/a/b5a626/32.png) [@Antonio\_Marin\_Cerezu](https://forum.ansible.com/u/Antonio_Marin_Cerezu)\
**Post date:** [January 5, 2014, 5:21pm UTC](https://forum.ansible.com/t/variable-name-composition/14274/1 "2014-01-05T17:21:14Z")

</div>

Hello,

I'm trying to compose a variable name with another variable, to keep the variables for each host on a single file/definition.

It looks like the following:

vars.yml:

netconf:  
&nbsp;&nbsp;&nbsp;&nbsp;iface:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;eth1  
&nbsp;&nbsp;&nbsp;&nbsp;ip:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;host-1:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;172.16.1.100  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;host-2:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;172.16.1.101  
&nbsp;&nbsp;&nbsp;&nbsp;mask:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;host-1:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;255.255.255.252  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;host-2:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;255.255.255.252

Inventory:

[test]  
host-1  
host-2

playbook.yml:

- hosts: test  
- tasks:  
&nbsp;&nbsp;&nbsp;- debug: msg="{{ netconf.ip.{{ ansible\_hostname }} }}"

I know it can be done loading a different vars file for each host, but I would like to keep them together on a single file. Also this composition schema can be applied to other situations.

Anyone knows if It's possible to achieve that behavior?

BR,  
Antonio

---

<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:** [January 5, 2014, 6:59pm UTC](https://forum.ansible.com/t/variable-name-composition/14274/2 "2014-01-05T18:59:20Z")

</div>

Here is how you can construct variable names programatically:

[http://docs.ansible.com/faq.html#how-do-i-access-a-variable-name-programatically](http://docs.ansible.com/faq.html#how-do-i-access-a-variable-name-programatically)

You cannot nest templates inside each other to construct variable names.
