# docker\_container unable to convert etc\_hosts to dict

**URL:** <https://forum.ansible.com/t/docker-container-unable-to-convert-etc-hosts-to-dict/25993>\
**Category:** Ansible Project\
**Created:** [November 10, 2017, 3:11pm UTC](https://forum.ansible.com/t/docker-container-unable-to-convert-etc-hosts-to-dict/25993 "2017-11-10T15:11:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Bush](https://avatars.discourse-cdn.com/v4/letter/d/c89c15/32.png) [@David\_Bush](https://forum.ansible.com/u/David_Bush)\
**Post date:** [November 10, 2017, 3:11pm UTC](https://forum.ansible.com/t/docker-container-unable-to-convert-etc-hosts-to-dict/25993/1 "2017-11-10T15:11:27Z")

</div>

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
