Loading variables from .env files in Ansible
Ansible has various ways of looking up data from outside sources, including plain text password files, CSV files and INI files. But it doesn't seem to have a lookup for .env files, as used in Laravel projects, also available for PHP, Ruby, Node.js, Python and others.
One option is to launch Ansible with the Ruby dotenv
command line script... But that requires Ruby, which seems like overkill to me.
So here is a simpler solution that I use. It consists of:
- The
.env
file itself - A small shell script that loads the
.env
file into environment variables -ansible-playbook.sh
- The playbook, which reads from the environment variables into Ansible variables
This comment has been minimized.
asfaltboy commentedJul 23, 2018
There's also python-dotenv if you already have python installed (and if you're using Ansible you probably do):