Concatenate variable name with 2 other variables name ?

Hi,

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

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 ?

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

Karsten

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.