I need to add the hosts that my docker container needs to contact, to the /etc/hosts file. The docker_container module has a provision for that but it’s not working when I set etc_hosts to a variable. The error is:
argument etc_hosts is of type <type ‘str’> and we were unable to convert to dict: dictionary requested, could not parse JSON or key=value
The task looks like this:
- name: Create mongo config server
become: true
docker_container:
name: mongoconfig
image: mongo
command: mongod --configsvr --replSet cfgrs --dbpath /data/configdb
state: started
restart_policy: unless-stopped
etc_hosts: docker_hosts
etc_hosts: >
{
“vegeta”: “192.168.77.6”,
“piccolo” : “192.168.77.7”,
“gohan” : “192.168.77.5”
}
volumes:
- mongo_config: /data/configdb
ports:
- “27019:27019”
When I print docker_hosts, it looks like this:
TASK [Display docker_hosts] ****************************************************
ok: [gohan] => {
“docker_hosts”: {
“gohan”: “192.168.77.5”,
“piccolo”: “192.168.77.7”,
“vegeta”: “192.168.77.6”
}
}
If I uncomment the etc_hosts section above it works which is nice except I can’t be hard coding the values in real life. I don’t see any difference between the hard coded structure and the contents of the variable.
Any clues as to why the variable doesn’t work?
Thanks