Hi
In v1.7.2 It was possible to do this i a template:
{{ vars[‘prefix_’ + {{ item.env }} + ‘_postfix’ ] | get_something }}
But it’s not working anymore in v.1.8.x. It just say that variable ‘prefix_main_postfix’ does not exist in dict
Can i somehow concat a string and use it as variable name in Ansible v.1.8.x?
I'm not sure this would have worked in older versions. Either way, don't
nest those braces, just use plain variables:
{{ vars['prefix_' + item.env + '_postfix' ] | get_something }}
Hi
Typo error. I meant
{{ vars[‘prefix_’ + item.env + ‘_postfix’ ] | get_something }}
This is not working anymore in v1.8.4 If I switch back to v.1.7.2 it’s working fine.
However if I type
{{ prefix_main_postfix | get_something }} in v.1.8.4 it’s working fine
Your latter example strike me as being obvious.
Is the varsdict meant to be something special?
Maybe it obvious but it is just to tell you that the variable exist. We use the vars like this:
myvars.yml:
prefix_main_postfix: some_value
master yml:
Try taking out the middle curly braces. So like:
{{ ‘prefix_’ + item.env + ‘_postfix’ | get_something }}
If you are declaring vars with the vars construct, you don’t need to reference vars as a dict, the key/values are directly available.
Let me know if that helps.
Hi
It does not work because get_something can’t parse the string “prefix_main_postfix” I need the value.
If I remove “| get_something” like this:
{{ ‘prefix_’ + item.env + ‘_postfix’ }}
it just print the text ‘prefix_main_postfix’