Testing ansible in docker container - how to set networks?

I write this post to Docker for Mac not General, since I think this problem is quite related with OSX network settings. If not, tell me so I can move this to other section.

  • This post is quite relevant with Ansible

I am trying to build test environments for ansible with following conditions.

  • Using centos docker container for ansible
  • Using centos docker containers for targets

All of 3 containers run successfully, but when I try to deploy to targets via ansible, the console saids
fatal: []: UNREACHABLE! => {"changed": false, "msg": "[Errno None] Unable to connect to port 9800 on", "unreachable": true}

Following is what I did in ansible-centos docker container.
First, this is my ansible hosts file.


Second, here is playbook.yml

# This playbook deploys a docker image centos:latest

- hosts: docker-hosts
  remote_user: root
  become: yes
  become_method: sudo

    - name: pulling docker image
        name: centos

Finally, I ran with following command
ansible-playbook playbook.yml -f 10

I have tried this with and, both failed.(in hosts file)

How can I deploy ansible-docker to another docker containers in same machine?
Thanks :+1: