How to connect docker nodes with ansible master

0 votes
Hi Guys,

I am new to Ansible. I want to connect docker nodes with an Ansible master node. How can I do that?
Aug 27, 2020 in Ansible by akhtar
• 38,260 points
1,661 views

1 answer to this question.

0 votes

Hi@akhtar,

You need a running container first, and you'll need to add the hostname to Ansible's inventory. One way to do it is to write an initial play that runs a container using the docker module and then uses the add_host module to add to the inventory. You can see the below example.

- name: start up a docker container
  hosts: localhost
  vars:
    base_image: ubuntu
    docker_hostname: webcontainer
  tasks:
    - name: start up a docker container by running bash
      local_action: docker image={{ base_image }} name={{ docker_hostname }} detach=yes tty=yes command=bash
    - name: add the host
      add_host: name={{ docker_hostname }}
- name: configure the web container
  hosts: webcontainer
  connection: docker
  tasks:
   - ...
answered Aug 27, 2020 by MD
• 95,460 points

Related Questions In Ansible

0 votes
1 answer

How to use Ansible git module pull a branch with local changes?

You cannot achieve it using the git ...READ MORE

answered Jul 9, 2018 in Ansible by Atul
• 10,240 points
7,109 views
0 votes
1 answer

How to pull a docker image using Ansible playbook?

Did you try using this? https://docs.ansible.com/ansible/latest/colle ...READ MORE

answered Nov 5, 2020 in Ansible by undermink
10,901 views
0 votes
1 answer

How to create a docker container using Ansible playbook?

Hi@akhtar, You can use the docker_container module in ...READ MORE

answered Aug 8, 2020 in Ansible by MD
• 95,460 points
4,362 views
0 votes
2 answers

How to create a directory in remote nodes using Ansible-Playbook?

You can read install and setup apache ...READ MORE

answered Aug 23, 2020 in Ansible by anonymous
• 160 points
4,327 views
+2 votes
1 answer
+2 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 58,020 points
2,737 views
0 votes
1 answer

How to start a docker container with healthstatus using Ansible?

Hi@akhtar, You can use the docker_container module in ...READ MORE

answered Sep 20, 2020 in Ansible by MD
• 95,460 points
3,063 views
0 votes
1 answer

How to create a group of Managed Nodes in Ansible?

Hi@akhtar, You can use tags in your inventory ...READ MORE

answered Aug 1, 2020 in Ansible by MD
• 95,460 points
1,293 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP