how to use dynamic calling of a variable which is present in vars file

Hi All,

My variable file:

VISEBS_SYSTEM: password

My yaml.file:

I’ll be passing a argument to my playbook as -e “src=VISEBS”, in my playbook i am trying to get dynamically the VISEBS_SYSTEM value. any suggestions

  • include_vars: variable_file

  • debug:
    msg: “{{ ‘{{src}}_SYSTEM’ }}”

as {{src}} will be replaced by VISEBS, i’m thinking that it will transform to {{VISEBS_SYSTEM}} which will finally print “password”, but its not happening what is the
exact way to achieve this.

You can't stack curly brackets, so the solution is

   msg: "{{ vars[src ~ '_SYSTEM' }}"

~ (tilde) is used for concatenate strings in Jinja

Hi Kai,

Thanks, it worked, but where can i find these kind of descriptions in ansible. as the ansible doc’s didn’t have these kind of docs i guess.

The FAQ covers some of the pitfalls
http://docs.ansible.com/ansible/latest/faq.html#when-should-i-use-also-how-to-interpolate-variables-or-dynamic-variable-names

Since this is Jinja maybe it's documented there also.

sure, thanks kai