Ansible playbook that will retrieve new docker container IP and dynamically update the Ansible inventory and configure webserver inside that container.
3 min readJan 16, 2021
--
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.