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

**URL:** <https://forum.ansible.com/t/how-to-use-dynamic-calling-of-a-variable-which-is-present-in-vars-file/26554>\
**Category:** Ansible Project\
**Created:** [January 24, 2018, 11:09am UTC](https://forum.ansible.com/t/how-to-use-dynamic-calling-of-a-variable-which-is-present-in-vars-file/26554 "2018-01-24T11:09:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gopi\_Krishna](https://avatars.discourse-cdn.com/v4/letter/g/d9b06d/32.png) [@Gopi\_Krishna](https://forum.ansible.com/u/Gopi_Krishna)\
**Post date:** [January 24, 2018, 11:09am UTC](https://forum.ansible.com/t/how-to-use-dynamic-calling-of-a-variable-which-is-present-in-vars-file/26554/1 "2018-01-24T11:09:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [January 24, 2018, 12:00pm UTC](https://forum.ansible.com/t/how-to-use-dynamic-calling-of-a-variable-which-is-present-in-vars-file/26554/2 "2018-01-24T12:00:17Z")

</div>

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

&nbsp;&nbsp;&nbsp;msg: "{{ vars[src ~ '\_SYSTEM' }}"

~ (tilde) is used for concatenate strings in Jinja

---

<div class="post-metadata">

**Author:** ![Gopi\_Krishna](https://avatars.discourse-cdn.com/v4/letter/g/d9b06d/32.png) [@Gopi\_Krishna](https://forum.ansible.com/u/Gopi_Krishna)\
**Post date:** [January 25, 2018, 5:44am UTC](https://forum.ansible.com/t/how-to-use-dynamic-calling-of-a-variable-which-is-present-in-vars-file/26554/3 "2018-01-25T05:44:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [January 25, 2018, 6:43am UTC](https://forum.ansible.com/t/how-to-use-dynamic-calling-of-a-variable-which-is-present-in-vars-file/26554/4 "2018-01-25T06:43:11Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![Gopi\_Krishna](https://avatars.discourse-cdn.com/v4/letter/g/d9b06d/32.png) [@Gopi\_Krishna](https://forum.ansible.com/u/Gopi_Krishna)\
**Post date:** [January 25, 2018, 2:02pm UTC](https://forum.ansible.com/t/how-to-use-dynamic-calling-of-a-variable-which-is-present-in-vars-file/26554/5 "2018-01-25T14:02:06Z")

</div>

sure, thanks kai
