扩展角色变量Ansible

扩展角色变量Ansible,ansible,ansible-role,Ansible,Ansible Role,我有一个负责任的角色。在这个角色中,我有vars/main.yml文件。在同一目录中,我希望有包含vault加密变量的“secret.yml”文件。“main.yml”文件从secret.yml中提取角色范围的变量的语法是什么 secret.yml内容: --- var1: value1 var2: value2 --- - name: Pull variables include_vars: secret.yml --- - include: secret.yml 我试过: main

我有一个负责任的角色。在这个角色中,我有vars/main.yml文件。在同一目录中,我希望有包含vault加密变量的“secret.yml”文件。“main.yml”文件从secret.yml中提取角色范围的变量的语法是什么

secret.yml内容:

---
var1: value1
var2: value2
---
- name: Pull variables
  include_vars: secret.yml
---
- include: secret.yml
我试过:

main.yml内容:

---
var1: value1
var2: value2
---
- name: Pull variables
  include_vars: secret.yml
---
- include: secret.yml
错误:

→ ./test_deploy.sh
ERROR! failed to combine variables, expected dicts but got a 'dict' and a 'AnsibleSequence':
{}
[{"name": "Pull variables", "include_vars": "secret.yml"}]
→ ./test_deploy.sh
ERROR! failed to combine variables, expected dicts but got a 'dict' and a 'AnsibleSequence':
{}
[{"include": "secret.yml"}]
main.yml内容:

---
var1: value1
var2: value2
---
- name: Pull variables
  include_vars: secret.yml
---
- include: secret.yml
错误:

→ ./test_deploy.sh
ERROR! failed to combine variables, expected dicts but got a 'dict' and a 'AnsibleSequence':
{}
[{"name": "Pull variables", "include_vars": "secret.yml"}]
→ ./test_deploy.sh
ERROR! failed to combine variables, expected dicts but got a 'dict' and a 'AnsibleSequence':
{}
[{"include": "secret.yml"}]

Ansible甚至允许这样的导入吗?

您不能在
vars/main.yml
中包含变量,您必须从
tasks/main.yml
=>
include\u vars:vars/secret.yml
中实际执行此操作。同时,在角色中包含保险库通常是个坏主意。您应该从您的剧本/目录中加载它们并将它们传递给您的角色。您不能在
vars/main.yml
中包含变量,您必须从
tasks/main.yml
=>
include\u vars:vars/secret.yml
中实际执行此操作。同时,在角色中包含保险库通常是个坏主意。您应该从您的剧本/清单中加载它们,并将它们传递给您的角色。