I have a list of dictionary variables something like below in vars file.
App01:
B : value2
C : value3
App02:
C : value5
B : value6
And so on...
When I run my playbook with -e option app=01 or app=App01
I want to use App01 variables in with_items in my task .
How can I achieve this?
I have a list of dictionary variables something like below in vars file.
App01:
A : value1
B : value2
C : value3
App02:
A : value4
C : value5
B : value6
And so on...
When I run my playbook with -e option app=01
"{{ hostvars[inventory_hostname]['App' ~ app] }}"
or app=App01
"{{ hostvars[inventory_hostname][app] }}"
I want to use App01 variables in with_items in my task .
App01 and App02 is not a list so you can't use with_items, but you could use with_dict instead.
Hi Kai,
Im using roles/vars file, so how do I achieve it?
App01:
B : value2
C : value3
App02:
C : value5
B : value6
And so on…
Also passing different values now, when -e app=data01_kerb something like this, if it has 01 , then choose App01’s dictionary ’
if app=data02_syn then choose App02’s dictionary…
is this possible?
Im passing app=data01_try , coz Im trying to derive/set_fact another variable from this value.
Any suggestions would be helpfull.
or any best way to achive this?
system
(system)
May 13, 2019, 2:10pm
4
To decide which var to use:
mydict: {{ '01' in app|ternary('App01', 'App02') }}
Then you can use via:
lookup('vars', mydict)