# Concatenate variable name with 2 other variables name ?

**URL:** <https://forum.ansible.com/t/concatenate-variable-name-with-2-other-variables-name/21716>\
**Category:** Ansible Developer\
**Created:** [June 9, 2016, 8:25am UTC](https://forum.ansible.com/t/concatenate-variable-name-with-2-other-variables-name/21716 "2016-06-09T08:25:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Clement\_VALENTIN](https://avatars.discourse-cdn.com/v4/letter/c/839c29/32.png) [@Clement\_VALENTIN](https://forum.ansible.com/u/Clement_VALENTIN)\
**Post date:** [June 9, 2016, 8:25am UTC](https://forum.ansible.com/t/concatenate-variable-name-with-2-other-variables-name/21716/1 "2016-06-09T08:25:43Z")

</div>

Hi,

I try to concatenate 2 variables value to form one another variable but i don’t found how to do this 😕

_Exemple:_

> group\_host\_type:
> 
> - HOST1:  
> node\_id: 0
> - HOST2:  
> node\_id: 1

I want to use “group\_host\_type” in playbook with host to use dynamics variable according to my server.

_Exemple (doesn’t work) :_

> - debug: msg=“{{ {{ group\_hybris\_host\_type }}.{{ inventory\_hostname }}.node\_id }}”

=\> Return 0 if on HOST1 server and 1 on HOST2 server.

Is it possible ?

---

<div class="post-metadata">

**Author:** ![Karsten](https://avatars.discourse-cdn.com/v4/letter/k/e47c2d/32.png) [@Karsten](https://forum.ansible.com/u/Karsten)\
**Post date:** [June 9, 2016, 10:30am UTC](https://forum.ansible.com/t/concatenate-variable-name-with-2-other-variables-name/21716/2 "2016-06-09T10:30:37Z")

</div>

Hi,

i think

`

- debug: msg=“{{ group\_host\_type[inventory\_hostname].node\_id }}”  
`

should work. I’m not sure if the declaration of group\_type is correct, though. I think it should be:

`  
group\_host\_type: {  
‘HOST1’: { ‘node\_id’: 0 },  
‘HOST2’: { ‘node\_id’: 1}  
}

`

but it might just be the case that i don’t always get yaml and prefer using curly braces instead of hyphens and intendation 😉

Karsten

---

<div class="post-metadata">

**Author:** ![Jonathan\_Davila](https://avatars.discourse-cdn.com/v4/letter/j/e0b2c6/32.png) [@Jonathan\_Davila](https://forum.ansible.com/u/Jonathan_Davila)\
**Post date:** [June 9, 2016, 4:35pm UTC](https://forum.ansible.com/t/concatenate-variable-name-with-2-other-variables-name/21716/3 "2016-06-09T16:35:31Z")

</div>

This is question for the ansible-project mailing list. This list is more about extending ansible or modifying ansible via python.

Your data structure is correct, however, the expression Karsten referenced would be proper way to grab that var.
