[英]In ansible-playbook I'm getting an error 'foo' is undefined running this playbook
Any ideas why this happens?任何想法为什么会发生这种情况?
undefined variable - The error was: 'foo' is undefined.未定义的变量 - 错误是:“foo”未定义。 I've tried using test.vars in yaml (test.yml) also.
我也尝试在 yaml (test.yml) 中使用 test.vars。
test.yml测试.yml
---
- hosts: all
roles:
- test
roles/test/tasks/main.yml角色/测试/任务/main.yml
- name: test
debug:
msg: "{{ foo }}"
group_vars/test.vars group_vars/test.vars
foo=bar
inventory存货
[all]
localhost
ansible-playbook -i inventory --extra-vars group_vars/@test.vars test.yml
They're called group_vars because they're related to the hosts group name.它们被称为 group_vars 因为它们与主机组名称相关。
[all]
the group name should be [test]
in the inventory file and in the main playbook.[test]
而不是[all]
。test.yml
test.yml
foo: bar
foo: bar
After these changes, there is no need to pass the file on the command line, because ansible will detect it automatically:做完这些改动后,就不需要在命令行传递文件了,因为ansible会自动检测:
ansible-playbook -i inventory test.yml
I found the answer is moving the @
outside, so;我发现答案是将
@
移到外面,所以; it looks like this:它看起来像这样:
--extra-vars @group_vars/test.vars
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.