I’m trying to setup a docker container from ansible with its volumes defined in a yml file passed as extra_vars.
The setup is quite simple:
config.yml
`
shared_folders:
- /Users/roger/Code/one:/one
- /Users/roger/Code/two:/two
`
inventory.yml
all: hosts: docker: vars: ansible_connection: docker
playbook.yml
`
-
name: Create our container
hosts: localhost
tasks: -
name: Debug shared_folders
debug:
msg: ‘{{ shared_folders }}’ -
debug: msg=“{{ item }}”
with_items: ‘{{shared_folders}}’ -
name: Create our container
hosts: localhost
tasks: -
docker_container:
name: docker
hostname: docker
image: ‘ubuntu:trusty’
command: [“sleep”, “1d”]
devices: ‘{{ shared_folders }}’
`
the debug shows the proper info, but the devices parameter is not rendered properly.
`
ansible-playbook playbook.yml -i inventory.yml --extra-vars “@config.yml”
PLAY [Create our container] ********************************************************************************************************************************
TASK [Gathering Facts] *************************************************************************************************************************************
ok: [localhost]
TASK [Debug shared_folders] ********************************************************************************************************************************
ok: [localhost] => {
“msg”: [
“/Users/roger/Code/one:/one”,
“/Users/roger/Code/two:/two”
]
}
TASK [debug] ***********************************************************************************************************************************************
ok: [localhost] => (item=/Users/roger/Code/one:/one) => {
“msg”: “/Users/roger/Code/one:/one”
}
ok: [localhost] => (item=/Users/roger/Code/two:/two) => {
“msg”: “/Users/roger/Code/two:/two”
}
PLAY [Create our container] ********************************************************************************************************************************
TASK [Gathering Facts] *************************************************************************************************************************************
ok: [localhost]
TASK [docker_container] ************************************************************************************************************************************
fatal: [localhost]: FAILED! => {“changed”: false, “msg”: “Error starting container 4dd1d94a025a0104a90713c528a8bac4b1c07241f91a6838127dced2383ad7fe: 500 Server Error: Internal Server Error ("b’{"message":"error gathering device information while adding custom device \\"/Users/roger/Code/one\\": not a device node"}'")”}
PLAY RECAP *************************************************************************************************************************************************
localhost : ok=4 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
`
Looks like each list member is extra escaped.
Any idea how to overcome this problem?
Thanks!