2017-08-18 82 views
1

我有一个剧本我想转换成一个模板,它使用include其他地方包括,并覆盖了几个变量,像这样:与使用vars_files包括ansible

$ cat env_demo.yml 
--- 
- include: template_standalone.yml 
    vars: 
    hosts: demo.example.com 
    environment_name: "Demo environment" 

这工作得很好,但那么我想加密的一些变量,像这样:

$ cat env_demo_secret.yml 
--- 
- include: template_standalone.yml 
    vars: 
    hosts: demo.example.com 
    vars_files: 
    - secrets/demo.example.com.yml 

现在我得到这个错误:

ERROR! 'vars_files' is not a valid attribute for a PlaybookInclude 

template_standalone.yml包含不同的角色列表...:

$ cat template_standalone.yml 
--- 
- name: Setting up standalone environment 
    hosts: "{{ hosts }}" 
    roles: 
    - role: php7 
    - role: nginx 
    ... 

...这需要配置像服务器密码等,我宁愿不以明文在主文件。有什么想法,我可以做什么呢?

回答

1

vars_files不支持包括剧本(如Ansible 2.3)

您可以选择使用额外的变量文件:

ansible-playbook -e @secrets/demo.example.com.yml env_demo.yml 

或者使用组变量立案all组 - 把你的加密文件到./group_vars/all/demo.example.com.yml

+0

谢谢,额外的变量方法适合我。我只是添加一条评论,说你需要指定它。 –