Testing ansible in docker container – how to set networks?

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

Source – docker.com

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: [127.0.0.1]: UNREACHABLE! => {"changed": false, "msg": "[Errno None] Unable to connect to port 9800 on 127.0.0.1", "unreachable": true}

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

[docker-hosts]
127.0.0.1:9800
127.0.0.1:9801

Second, here is playbook.yml

---
# This playbook deploys a docker image centos:latest

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

  tasks:
    - name: pulling docker image
      docker_image:
        name: centos

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

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

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x