Available extra stock as nested json
I am trying to use unsible for parameterized docker deployment. I want to be able to specify image, version and various environment variables on the command line.
Image, version, etc. can be specified directly, but the docker module env parameter requires a dictionary. Here's an example of an abridged book:
-name: some deployment
docker:
[..]
name: myname
[..]
env:
FOO: bar
ANOTHERFOO: anotherbar
Environment variables are selected at runtime, so they cannot be defined directly in additional redundant vars. At the moment it looks like this:
-name: some deployment
docker:
[..]
name: "{{ name }}"
[..]
env: "{{ env }}"
Since env is a nested dictionary, we must provide -extra-vars as nested json. I expected the following to work:
./ansible-playbook [..] --extra-vars '{"name":"myname", "env":{"FOO":"bar", "ANOTHERFOO":"anotherbar"}}' [..]
After starting the container, the env values do not exist. Supplying the json directly in the tutorial for testing works.
I tried the following json without any results:
{"name":"myname", "env":{"FOO":"bar", "ANOTHERFOO":"anotherbar"}}
{"name":"myname", "env":[{"FOO":"bar"}, {"ANOTHERFOO":"anotherbar"}]}
How do you supply and use the nested dictionary via the command line or is it a limitation of the Jinja2 templating engine.
source to share
The correct structure to use if you need a voice recorder in your YAML / ansible playbook is a nested json supplied with --extra-vars, as in the example:
./ansible-playbook [..] --extra-vars '{"name":"myname", "env":{"FOO":"bar", "ANOTHERFOO":"anotherbar"}}' [..]
and
-name: some deployment
docker:
[..]
name: "{{ name }}"
[..]
env: "{{ env }}"
For testing purposes, I used environment
on my system, which I shortened to env
as an example. The problem environment
is a reserved variable and always gets overridden.
source to share