Ansible-包含来自远程主机的vars文件 [英] Ansible - include vars file from remote host

查看:67
本文介绍了Ansible-包含来自远程主机的vars文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想包含远程主机上文件中的变量,而不是运行Ansible的控制计算机.

I would like to include variables from a file on the remote host, rather than the control machine Ansible is running on.

例如,我有一个/var/database_credentials.yml文件(在我的网络服务器上)

For example I have a file /var/database_credentials.yml (on my webserver)

将文件中的变量添加到hostvars以便在模板中使用它们的最佳方法是什么?

What's the best way to add variables from that file to hostvars so that I can use them in a template?

include_vars模块仅从控制计算机获取文件.我可以使用fetch模块,但这似乎是不必要的步骤.

The include_vars module only takes files from the control machine. I could use the fetch module but that seems like an unnecessary step.

推荐答案

将它与/etc/ansible/facts.d 集成起来应该不难.

It should not be hard to integrate that with /etc/ansible/facts.d.

您可以在该目录中存储JSON文件,INI文件或可执行脚本,并且在执行安装模块后,内容/输出将作为服务器事实提供.

You can store JSON files, INI files or executable scripts in that directory and the content/output will be available as server facts after the setup module was executed.

我不确定是否需要YAML.您可能很幸运,只需将符号链接添加到文件/var/database_credentials.yml 即可.(文档中未提及YAML,但如果不支持YAML,这将很奇怪,因为Ansible中的几乎所有内容都基于YAML).如果没有,则可以用您喜欢的语言创建一个脚本,该脚本读取该文件并输出JSON对象.

I'm not sure it will take YAML. You might be lucky and it'll work to simply add a symlink to your file /var/database_credentials.yml. (YAML is not mentioned in the docs but it would be strange if YAML is not supported since pretty much everything in Ansible is based on YAML) If not, you can create a script in the language you prefer which reads that file and outputs a JSON object.

请参见本地事实(Facts.d)在文档中.

这篇关于Ansible-包含来自远程主机的vars文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆