Variable of variable in Ansible Playbook -
i trying access variables defined in group_vars
group_vars/all
parent1: child1: somevalue1 child2: somevalue2 parent2: child1: somevalue1 child2: somevalue2 now passing parent detail ansible playbook vars this
ansible-playbook playbook.yml -e "parent=parent1" now how can access parent1.child1 value parent1 comes in {{ parent }} vars?
my playbook this:-
playbook.yml
- hosts: local user: roop gather_facts: no connection: local vars: parent: "" tasks: #get parent value - debug: msg={{ parent }} #trying access parent1.child1 value here - debug: msg={{ {{ parent }}.child1 }} playbook output:-
play [local] ****************************************************************** task: [debug msg=local] ******************************************************* ok: [127.0.0.1] => { "msg": "parent1" } task: [debug msg={{{{parent}}.child1}}] *************************************** ok: [127.0.0.1] => { "msg": "{{{{parent}}.child1}}" } play recap ******************************************************************** 127.0.0.1 : ok=2 changed=0 unreachable=0 failed=0 can guide how can achieve or alternate solution.
how have done this
change group_vars/all below:-
data: parent1: child1: somevalue1 child2: somevalue2 parent2: child1: somevalue1 child2: somevalue2 change in playbook.yml:-
- debug: msg={{ data[parent].child1 }} please share if have better solution :)
Comments
Post a Comment