剧本
ansible 2.4.0
config file = None
configured module search path = [u'/Users/szabop/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /Library/Python/2.7/site-packages/ansible
executable location = /usr/local/bin/ansible
python version = 2.7.10 (default, Jul 14 2015, 19:46:27) [GCC 4.2.1 Compatible Apple LLVM 6.0
我正在从另一个目录导入角色和角色,所以我在ansible.cfg中
[defaults]
roles_path = ../../../deployment/playbooks/roles
OSX 10.10.5
当我尝试通过使用vars_files中的变量动态确定要导入的库文件时(单元测试不应使用生产密码!),对于导入的播放机,我无法使用group_vars,host_vars或事实来做到这一点。在设置播放中设置。 我只能使用ansible命令行参数。
ansible-playbook -t app_test -i inventories/localhost/local.hosts unit.yml
---
#
# network.yml
#
- name: Setup the networks
hosts: dockerhosts
vars_files:
- demoVars.yml
- "{{ vault_file }}" # this will only be valid if declared on the ansible command line.
roles:
- role: debug # note this will print out a valid {{ vault_file }} in all cases (but comment out the vars_files line or it will error first)
- role: network_setup
options:
internal: "{{ networks.internal }}"
external: "{{ networks.external }}"
nginx: "{{ networks.nginx }}"
tags:
- setup
- standalone
- app_test
# unit.yml
---
- name: create facts used to compose variables later in this playbook
hosts: dockerhosts
vars:
esTmpDir: "/tmp/es"
roles:
- role: unitenv_setup
tags:
- app_test
- import_playbook: ../../../deployment/playbooks/network.yml
如果使用--extra-vars
在ansible命令行上指定了变量vault_file
则脚本可以正常运行。 从清单文件设置vault_file
或在unitenv_setup
中将其设置为事实时,它应该可以正常运行,但是不会
使用除命令行以外的任何方法来设置vault_file
,我得到以下错误:
PLAY [Setup the networks] *********************************************************************
ERROR! vars file {{ vault_file }} was not found
极其冗长的模式:
ETA: ran handlers
META: ran handlers
Read vars_file 'demoVars.yml'
skipping vars_file '{{ vault_file }}' due to an undefined variable
Read vars_file 'demoVars.yml'
skipping vars_file '{{ vault_file }}' due to an undefined variable
PLAY [Setup the networks] *********************************************************************
Read vars_file 'demoVars.yml'
ERROR! vars file {{ vault_file }} was not found
我注意到我的生产环境有些复杂,我似乎无法进行简单的共享复制。 无论如何,这是再现
嗨!
非常感谢您提交给Ansible。 这对我们意义重大。
我们认为您所提交的机票有些被误解了,因为一件事情的工作方式与所述的有所不同。
事实,主机和组变量..基本上,任何与“主机相关的变量”都不适用于vars_files
,此时只能播放作用域变量或额外变量。 请改用include_vars
任务。
将来,这可能是一个更适合用户列表的主题,如果您需要以上帮助,也可以在此处发布。
再次感谢您对此事以及您对Ansible的关注!
也许您应该修复文档? 不太明显...
最有用的评论
也许您应该修复文档? 不太明显...