我正在尝试访问在group_vars
group_vars/全部
parent1:
child1: somevalue1
child2: somevalue2
parent2:
child1: somevalue1
child2: somevalue2
现在我正在传递parent
这样的 ansible playbook extra vars 的细节
ansible-playbook playbook.yml -e "parent=parent1"
现在我如何访问vars中的parent1.child1
值?parent1
{{ parent }}
我的剧本看起来像这样:-
剧本.yml
- hosts: local
user: roop
gather_facts: no
connection: local
vars:
parent: ""
tasks:
#get parent value
- debug: msg={{ parent }}
#trying to access parent1.child1 value here
- debug: msg={{ {{ parent }}.child1 }}
剧本输出: -
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
任何人都可以指导我如何实现这个或任何替代解决方案。