I'm trying to use ansible for a parameterised docker deployment. I want to be able to specify image, version and various different environment variables via the command line.
Image, Version and so on can be specified directly but the env parameter of the docker module requires a dictionary. Here is a shortened playbook example:
-name: some deployment
docker:
[..]
name: myname
[..]
env:
FOO: bar
ANOTHERFOO: anotherbar
The environment variables are choosen during runtime, so it is not possible to define them directly in the supplied extra vars. The playbook looks like this at the moment:
-name: some deployment
docker:
[..]
name: "{{ name }}"
[..]
env: "{{ env }}"
Since env is a nested dictionary we need to supply the --extra-vars as nested json. I would expected the following to work:
./ansible-playbook [..] --extra-vars '{"name":"myname", "env":{"FOO":"bar", "ANOTHERFOO":"anotherbar"}}' [..]
After the container is running, the values of env are not there. Supplying the json directly in the playbook for testing purposes works.
I tried the following different json with no working results:
{"name":"myname", "env":{"FOO":"bar", "ANOTHERFOO":"anotherbar"}}
{"name":"myname", "env":[{"FOO":"bar"}, {"ANOTHERFOO":"anotherbar"}]}
How do you supply and use a nested dictionary via command line or is this a limitation of the Jinja2 template engine.
--extra-vars '{"pacman":"mrs","ghosts":["inky","pinky","clyde","sue"]}'
docs.ansible.com/ansible/… – udondan- debug: msg="{{ env[0].FOO }}"
. My Call:ansible-playbook -i inventory/test test.yml --extra-vars '{"name":"myname", "env":[{"FOO":"bar"}, {"ANOTHERFOO":"anotherbar"}]}'
and the output of the debug task:"msg": "bar"
. – udondanFOO
in the debug to show it not only is text but an accessible object. – udondan