I have the following (simplified) play:
- hosts: testing
roles:
- nginx
vars_files:
- config.yml
environment:
http_proxy: http://proxy.example.com:8080
Now, when I run my code, I can read process.env.http_proxy
. I would however like to be able to set other environment variables dynamically under environment
. For example, in my config.yml
I have the following:
application_variables:
- key: "NODE_ENV"
value: "production"
- key: "PORT"
value: "3000"
How would I get the values from application_variables
to be dynamically created under environment? I’ve tried a few different solutions I found out there to no avail.
2
Answers
You can feed the
environment
parameter from a templated Jinja expression, in your case:Then you have the choice to:
application_variables
list:combine
the dictionary created from theapplication_variables
with a variable defined at the in your playbook:As an example, the playbook:
Would give you:
Combine the environment
gives
Import the role
For example, given the simplified role
gives
Example of a complete playbook for testing