I'm passing env variables to a Docker container in an ansible playbook, how do I set an Ansible variable in the key in the key/value of an env?
So this:
- name: webproxy container
docker_container:
name: "webproxy"
image: "webproxy"
env:
SERVICE_443_NAME: "webproxy"
becomes this:
- name: webproxy container
docker_container:
name: "webproxy"
image: "webproxy"
env:
SERVICE_{{ port_number }}_NAME: "webproxy"
The key part in the key=value pairs will be converted into lowercase inside the ansible_local variable.
The easiest way to pass Pass Variables value to Ansible Playbook in the command line is using the extra variables parameter of the “ansible-playbook” command. This is very useful to combine your Ansible Playbook with some pre-existent automation or script.
The include_vars module can be used in a playbook or role to load variables from a file. Simply set the value of include_vars to a local file to load the variables it contains: --- # ./hello_world. yml - name: print greeting hosts: "*" tasks: - include_vars: name_vars.
Use JSON notation to define a dictionary with environment variables:
- name: webproxy container
docker_container:
name: "webproxy"
image: "webproxy"
env: '{ "SERVICE_{{ port_number }}_NAME": "webproxy" }'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With