【发布时间】:2015-09-25 17:00:00
【问题描述】:
我无法从 ansible 获取我的 jinja2 模板,以便能够读取在 group_vars/all.yml 中设置的全局变量。
** 我的问题是 **:我怎样才能让我的 j2 模板能够看到在group_vars/all.yml 中设置的全局变量?据我了解,group_vars/all 应该适用于所有群体。
我的ansible项目如下:
group_vars/
all.yml
playbooks/
roles/
some-role/
tasks/
main.yml
templates/
template.conf.j2
my-playbook.yml
tasks/main.yml
---
- name: do it
template:
src: template.conf.j2
dest: ...
模板/template.conf.j2
The global variable is: {{ GlobalVariable }}
group_vars/all.yml
GlobalVariable: something
当我运行 playbook 时,尝试编写该模板时出现错误。
AnsibleUndefinedVariable: One or more undefined variables: 'GlobalVariable' is undefined
【问题讨论】: