问题描述
在使用Ansible时,我试图使用拱形的vars文件存储私有变量,然后以相同的角色在另一个vars文件中使用私有变量. (来自"Vault伪叶子加密"的想法此处 )
In using Ansible, I'm trying to use a vaulted vars file to store private variables, and then using those in another vars file, in the same role. (The idea from 'Vault Pseudo leaf encryption' here.)
例如我有一个标准的vars文件roles/myrole/vars/main.yml
:
e.g. I have one standard vars file, roles/myrole/vars/main.yml
:
---
my_variable: '{{ my_variable_vaulted }}'
,然后是加密的roles/myrole/vars/vaulted_vars.yml
:
---
my_variable_vaulted: 'SECRET!'
但是当我运行剧本时,总是得到"ERROR!ERROR!'my_variable_vaulted'未定义".
But when I run the playbook I always get '"ERROR! ERROR! 'my_variable_vaulted' is undefined"'.
我尝试过不加密第二个文件,以确保它不是加密问题,并且出现了相同的错误.
I've tried it without encrypting the second file, to make sure it's not an issue with encryption, and I'm getting the same error.
推荐答案
my_variable_vaulted
不可用的原因是因为我没有包含变量文件.我以为角色vars/
目录中的所有文件都会被自动拾取,但是我认为vars/main.yml
只是这种情况.
The reason why my_variable_vaulted
wasn't available was because I hadn't included the variable file. I'd assumed that all files in a role's vars/
directory were picked up automatically, but I think that's only the case with vars/main.yml
.
因此,要使角色中的所有任务都可使用拱形变量,在roles/myrole/tasks/main.yml
中,我在所有任务之前添加了该变量:
So, to make the vaulted variables available to all tasks within the role, in roles/myrole/tasks/main.yml
I added this before all the tasks:
- include_vars: vars/vaulted_vars.yml
这篇关于在另一个var文件中使用一个Ansible var文件中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!