【发布时间】:2019-01-08 05:59:46
【问题描述】:
我正在尝试在本地运行剧本,但我希望角色的 task/main.yml 文件中的所有 var 都引用特定清单文件中的 group_var。
不幸的是,playbook 无法访问 group_vars 目录,就好像无法识别角色中指定的变量一样。
运行的命令如下:
/usr/local/bin/ansible-playbook --connection=local /opt/ansible/playbooks/create.yml -i ./inventory-file
但是在inventory文件同级目录的/group_vars目录下找不到group_vars
fatal: [127.0.0.1]: FAILED! => {
"msg": "The task includes an option with an undefined variable. The error was: 'admin_user_name' is undefined\n\nThe error appears to have been in '/opt/roles/create/tasks/main.yml': line 2, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n---\n- name: create org\n ^ here\n"
}
这是我的配置:
ansible-playbook 2.7.5
config file = /etc/ansible/ansible.cfg
configured module search path = ['/opt/ansible-modules']
ansible python module location = /usr/local/lib/python3.6/dist-packages/ansible
executable location = /usr/local/bin/ansible-playbook
python version = 3.6.3 (default, Oct 3 2017, 21:45:48) [GCC 7.2.0]
感谢任何帮助。
谢谢, dom
【问题讨论】:
-
您能否提供您的文件/目录结构以及库存主机文件的内容? group_vars 目录可以与 playbook 或库存文件位于同一目录中。由于您的连接是本地的,因此需要在清单文件中以“localhost”作为成员引用该组。
标签: ansible