Ansible - enable vars file from remote host

I would like to include the variables from the file on the remote host, and not in the Ansible control machine.

For example, I have a file / var / database _credentials.yml (on my web server)

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

The include_vars module only accepts files from the host machine. I could use a fetch module, but this seems like an unnecessary step.

+6
source share
1 answer

It is not difficult to integrate this with /etc/ansible/facts.d .

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

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

See Local Facts (Facts.d) in the docs.

+1
source

All Articles