Ansible playbook that will retrieve new docker container IP and dynamically update the Ansible inventory and configure webserver inside that container.

In this article, we will create an Ansible Playbook which will:

  • Install Docker
  • Launch Container
  • Update Inventory File
  • Configure Container as Web Server
  • Initially, the Inventory file is empty.
  • Ansible Configuration File.
  • Ansible Playbook to Install Docker and Update Inventory File.
  • Inventory.j2 file template.
  • Ansible Playbook to Configure a Docker Container. (I used my own docker image having sshd configured. You can get it from here.)
  • Running the docker_dynamic_ip.yml playbook.
  • IP has been added dynamically in the inventory file.
  • You can verify IP is Updated Correctly.
  • Now running docker_container.yml playbook to configure web server.
  • Docker Container has been launched Successfully.
  • Also, the Web Server is Working Perfectly. (I Exposed port 80 of container with port 1234 of Engine.)

For Github Link, click here.

For Ansible PlayBook to Launch Web-Server on Docker Container, click here.




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

AWS S3 in Elixir with ExAws

CS373 Fall 2020: Divya Manohar

‘coding (what is it good for)’

DATABASE : Basic concepts everyone should know

Useful resources from this week’s newsletter

AWS S3 vs EBS vs EFS

Core Data with Swift 4 for Beginners

3 Domain-Centric Architectures Every Software Developer Should Know

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Karan Agrawal

Karan Agrawal

More from Medium

How to Install OpenSpeedTest on Docker with Portainer

VPN Chaining with Wireguard

Install Grafana on Ubuntu / Rocky Linux & Fedora

Grafana Dashboard

How to self host in 2022?