从 Ansible 清单文件中,是否可以包含来自另一个文件的变量?
From an Ansible inventory file, is it possible to include variables from another file?
我的 Ansible 主机文件:
mybox.mydomain.com ansible_ssh_pass={{mypassword}}
变量 'mypassword' 在文件 "variables.yml" 中定义:
mypassword = somepassword
有什么方法可以将 "variables.yml" 中的变量包含在我的主机文件中?否则当我尝试 运行 一些 Ansible 命令时,我得到错误
the field 'password' has an invalid value, which appears to include a variable that is undefined. The error was: 'mypassword' is undefined
我问这个是因为最终我想使用 .yml 文件中的 Vault 加密变量(因为这是 Vault 加密单个变量的唯一方法)
将 variables.yml
放入库存附近的 group_vars/all/variables.yml
。
这会将 variables.yml
中的所有内容加载为清单中每个主机的组变量。
我的 Ansible 主机文件:
mybox.mydomain.com ansible_ssh_pass={{mypassword}}
变量 'mypassword' 在文件 "variables.yml" 中定义:
mypassword = somepassword
有什么方法可以将 "variables.yml" 中的变量包含在我的主机文件中?否则当我尝试 运行 一些 Ansible 命令时,我得到错误
the field 'password' has an invalid value, which appears to include a variable that is undefined. The error was: 'mypassword' is undefined
我问这个是因为最终我想使用 .yml 文件中的 Vault 加密变量(因为这是 Vault 加密单个变量的唯一方法)
将 variables.yml
放入库存附近的 group_vars/all/variables.yml
。
这会将 variables.yml
中的所有内容加载为清单中每个主机的组变量。