More dynamic variables

35 views
Skip to first unread message

Mark Tovey

unread,
Aug 21, 2019, 2:35:29 PM8/21/19
to Ansible Project

    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?


 

James Cassell

unread,
Aug 21, 2019, 8:40:55 PM8/21/19
to Ansible List
On Wed, Aug 21, 2019, at 2:35 PM, 'Mark Tovey' via Ansible Project wrote:
>
> 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

Mark Tovey - DSV

unread,
Aug 22, 2019, 11:13:22 AM8/22/19
to ansible...@googlegroups.com

Joe Langdon

unread,
Aug 22, 2019, 11:24:26 AM8/22/19
to ansible...@googlegroups.com
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 :-) 

You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/AM5PR0602MB2771EDE997589AD46EC3BB519EA50%40AM5PR0602MB2771.eurprd06.prod.outlook.com.


--

Joe Langdon

Sometimes when you think life is kicking you in the ass, it's actually just moving you quickly to a better place.


Mark Tovey - DSV

unread,
Aug 22, 2019, 11:26:07 AM8/22/19
to ansible...@googlegroups.com

 

    Hindsight is always 20:20 😊


To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages