How to set dynamic host inventory file for docker in Ansible

0 votes

Hi Guys,

I have launch containers in the remote system. I want to fetch the host name dynamically from the remote system and update the Ansible inventory dynamically. How can I do that?

Sep 20, 2020 in Ansible by akhtar
• 38,260 points
2,002 views

1 answer to this question.

0 votes

Hi@akhtar,

In a configuration especially a container setup such as Docker where the inventory file keeps constantly changing as you add or decommission servers, keeping tabs on the hosts defined in the inventory file becomes a real challenge. It becomes inconvenient going back to the host file and updating the list of hosts with their IP addresses. And this is where a dynamic inventory comes to play. You can find some scripts in python for docker. When you run the script using the Ansible command, it will update the inventory dynamically. You can download the script form the below link.

https://raw.githubusercontent.com/ansible/ansible/stable-2.9/contrib/inventory/docker.py

answered Sep 20, 2020 by MD
• 95,460 points

Related Questions In Ansible

0 votes
1 answer
0 votes
1 answer

What is the difference between the host file and an inventory file in ansible?

Actually both are same. hosts file is ...READ MORE

answered Feb 12, 2019 in Ansible by Amith
• 140 points
8,001 views
0 votes
2 answers

How to enable Inventory Cache plugin in Ansible?

Adding to @Farookh's answer, if the inventory ...READ MORE

answered Feb 20, 2019 in Ansible by Shalaka
2,383 views
0 votes
1 answer

How to add multiple lines in a file using Ansible playbook?

Hi@akhtar, You can update your file using lineinfile ...READ MORE

answered Sep 16, 2020 in Ansible by MD
• 95,460 points
26,629 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,714 views
0 votes
1 answer

How to overwrite the content of a file in remote systems using Ansible playbook?

Hi@akhtar, You can find one argument in the ...READ MORE

answered Aug 2, 2020 in Ansible by MD
• 95,460 points
14,401 views
0 votes
1 answer

How to validate the sudoers file before changing the file in Ansible?

Hi@akhtar, You can do this using lineinfile module ...READ MORE

answered Sep 2, 2020 in Ansible by MD
• 95,460 points
4,382 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