# More dynamic variables

**URL:** <https://forum.ansible.com/t/more-dynamic-variables/31094>\
**Category:** Ansible Project\
**Created:** [August 21, 2019, 6:35pm UTC](https://forum.ansible.com/t/more-dynamic-variables/31094 "2019-08-21T18:35:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mark.tovey](https://avatars.discourse-cdn.com/v4/letter/m/ce73a5/32.png) [@mark.tovey](https://forum.ansible.com/u/mark.tovey)\
**Post date:** [August 21, 2019, 6:35pm UTC](https://forum.ansible.com/t/more-dynamic-variables/31094/1 "2019-08-21T18:35:28Z")

</div>

I hate having to constantly go here to solve issues like this, especially when the issues I keep presenting are all so similar, but eventually I have to just give up trying to solve this on my own and ask.

I want to define a structure in a vars file that looks like the following:

> myos: {

> configdir: “/path/to/directory”,

> configfile: “filename”

> }

> my\_configdir: “{{ansible\_facts.distribution}}.configdir”

> my\_configfile: “{{ansible\_facts.configfile}}.configfile”

I want to do something similar to the following:

> stat:

> path: “{{my\_configdir}}/{{my\_configfile}}”

> register: result

Unfortunately, path is being resolved to “myos.configdir/myos.configfile”, not the expected “/path/to/directory/filename”. I have tried using various methods of concatenating variables together, including trying the ‘vars’ lookup plugin, but I have not been able to work this out after two days of trying. So, here I am, back at the well, looking for another answer. Does anyone have any advice?

---

<div class="post-metadata">

**Author:** ![cassell](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@cassell](https://forum.ansible.com/u/cassell)\
**Post date:** [August 22, 2019, 12:40am UTC](https://forum.ansible.com/t/more-dynamic-variables/31094/2 "2019-08-22T00:40:06Z")

</div>

> I hate having to constantly go here to solve issues like this,  
> especially when the issues I keep presenting are all so similar, but  
> eventually I have to just give up trying to solve this on my own and  
> ask.
> 
> I want to define a structure in a vars file that looks like the following:
> 
> \> myos: {  
> \> configdir: "/path/to/directory",  
> \> configfile: "filename"  
> \> }  
> \> my\_configdir: "{{ansible\_facts.distribution}}.configdir"

my\_configdir: "{{ (lookup('vars' ansible\_facts.distribution)).configdir }}"

And so on...

> \> my\_configfile: "{{ansible\_facts.configfile}}.configfile"
> 
> I want to do something similar to the following:
> 
> \> stat:  
> \> path: "{{my\_configdir}}/{{my\_configfile}}"  
> \> register: result  
> Unfortunately, path is being resolved to  
> "myos.configdir/myos.configfile", not the expected  
> "/path/to/directory/filename". I have tried using various methods of  
> concatenating variables together, including trying the 'vars' lookup  
> plugin, but I have not been able to work this out after two days of  
> trying. So, here I am, back at the well, looking for another answer.  
> Does anyone have any advice?

V/r,  
James Cassell

---

<div class="post-metadata">

**Author:** ![mark.tovey](https://avatars.discourse-cdn.com/v4/letter/m/ce73a5/32.png) [@mark.tovey](https://forum.ansible.com/u/mark.tovey)\
**Post date:** [August 22, 2019, 3:13pm UTC](https://forum.ansible.com/t/more-dynamic-variables/31094/3 "2019-08-22T15:13:13Z")

</div>

As usual, the answer is simple. I was trying to trying to include ".configdir" inside of the lookup plugin call. And now that I am looking at a working solution, I can see how this works. I can be very obtuse sometimes.  
&nbsp;&nbsp;&nbsp;&nbsp;Thanks again.  
&nbsp;&nbsp;&nbsp;&nbsp;-Mark

---

<div class="post-metadata">

**Author:** ![CaptainBrewing](https://avatars.discourse-cdn.com/v4/letter/c/76d3ee/32.png) [@CaptainBrewing](https://forum.ansible.com/u/CaptainBrewing)\
**Post date:** [August 22, 2019, 3:24pm UTC](https://forum.ansible.com/t/more-dynamic-variables/31094/4 "2019-08-22T15:24:06Z")

</div>

Seems perfect time to ask a question to me. You tried everything you could on your own. Life always looks easy after you are given the answer but by design is a struggle to get there 🙂

---

<div class="post-metadata">

**Author:** ![mark.tovey](https://avatars.discourse-cdn.com/v4/letter/m/ce73a5/32.png) [@mark.tovey](https://forum.ansible.com/u/mark.tovey)\
**Post date:** [August 22, 2019, 3:25pm UTC](https://forum.ansible.com/t/more-dynamic-variables/31094/5 "2019-08-22T15:25:55Z")

</div>

Hindsight is always 20:20 😊
