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