More dynamic variables

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?

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

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.
    Thanks again.
    -Mark

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

Hindsight is always 20:20 :blush: