docker_container unable to convert etc_hosts to dict

28 views
Skip to first unread message

David Bush

unread,
Nov 10, 2017, 10:11:27 AM11/10/17
to Ansible Project
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
Reply all
Reply to author
Forward
0 new messages