solved in a ugly way..
#not yet working in ansible release 2.3.x
# when: lookup('vars', item|basename, default=false)
when: confobjs[item|basename]|default(false)
vars:
confobjs: "{% set objs = {} %}\
{% set objs1 = objs|combine({'firstconfobj': firstconfobj})
if monitrc is defined %}\
{% set objs = obj1 %}\
{% set objs1 = objs|combine({'secondconfobj':
secondconfobj}) if allow_monitrc is defined %}\
{% set objs = obj1 %}\
#and so on
{{ objs }}"
Il giorno lunedì 11 marzo 2019 21:05:11 UTC+1, fusillator ha scritto:
>
> Hi all, I need to get the value of a variable whose name is saved in
> another one, in other words I need the lookup plugin vars
> Unfortunately I can't upgrade ansible to a release upper to 2.4, so I have
> to reinvent the wheel.. unpleasant feeling.
> Is there a way to implement it in another way?
>
> I tried like so
>
> # when: lookup('vars', item|basename, default=false)
> when: confobj
> vars:
> confobj: "{% set output = globals()[item|basename] if
> globals()[item|basename] is defined else false %}\
> {{ output }}"
>
> But the variable is not defined in the global namespace..
> Actually the problem is a little more simple.. the variable could be set
> in {host,group}_vars or in roles/*/{default,vars}
> For the former case I could get it thanks the available var plugin with
> host_vars[inventory_hostname][item|basename]
> but how to retrieve those variables set by roles stuff?
>
> regards
>
> Luca
>
>
>
>
>
>
>
>
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/dbda9fc2-2f5d-475a-850e-39cb5459e172%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.