【发布时间】:2015-12-13 01:24:54
【问题描述】:
我有以下 Ansible 设置:
playbook.yml
---
- hosts: all
sudo: true
vars_files:
- vars/all.yml
tasks:
- debug: msg="foo.bar = {{ foo.bar if foo.bar is defined else False }}"
- debug: msg="foo_bar = {{ foo_bar if foo_bar is defined else False }}"
vars/all.yml
---
foo:
greeting: "Hello, world!"
主机/制作
production ansible_ssh_host=xxx.xxx.xxx.xxx ansible_ssh_user=root
host_vars/production
---
foo:
bar: baz
foo_bar: baz
当我运行 ansible-playbook -i hosts/production playbook.yml 时,我得到以下结果:
TASK: [debug msg="foo.bar = {{ foo.bar if foo.bar is defined else False }}"] ***
ok: [production] => {
"msg": "foo.bar = False"
}
TASK: [debug msg="foo_bar = False"] *******************************
ok: [production] => {
"msg": "foo_bar = baz"
}
为什么我的嵌套主机 var foo.bar 不起作用,而顶级主机 var foo_bar 起作用?
【问题讨论】: