🔰Ansible playbook that will retrieve new Container IP and dynamically update the inventory and Configure web-server inside that Docker Container🔰

rishabhsharma
3 min readJan 12, 2021

ARTH — Task 14 👨🏻‍💻

Task Description📄

🔰 14.2 Further in ARTH — Task 10 have to create an Ansible playbook that will retrieve new Container IP and update the inventory. So that further Configuration of Webserver could be done inside that Container.

👉🏻Lets get started…😃

In this task I have used my own pre-created docker image which is enabled with ssh. So that Ansible can use ssh protocol to login to new docker container and configure webserver inside it.

In my case I am having Controller Node having IP 192.168.43.155 on which the ansible is installed

✔️Lets check the ansible version installed on my controller node :

# ansible --version

✔️ Initially inventory file is empty

# cat /root/ip.txt

✔️ Configuration file of ansible :

# vim /etc/ansible/ansible.cfg

🔶 Ansible Playbook :

# vim docker.yml
# vim docker-web.yml

✔️dockerip.txt file

✔️ task14_2.html file

✔️ Now let’s run the main Playbook:

# ansible-playbook docker.yml

✔️ Inventory file dynamically updated

✔️ Check Docker Service started and enabled:

✔️ Successfully Launched docker container with name myweb:

🔶 Now we can run our docker-web.yml playbook to configure webserver inside container:

# ansible-playbook docker-web.yml

Done! Now checking by Attaching to myweb container:

Now the webserver has been deployed on the docker container with the help of the Ansible Automation tool. So Let’s check our webpage from the browser :

TASK COMPLETED Successfully✌🏻👨🏻‍💻

Thanks for reading !!!😊✨

🔰Keep Learning ❗❗🔰Keep Sharing ❗❗

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

rishabhsharma
rishabhsharma

Written by rishabhsharma

Data Engineer | Azure Databricks | AWS | PySpark | DevOps | Machine Learning 🧠 | Kubernetes ☸️ | SQL 🛢

Responses (1)

Write a response

bro how u enabled ssh service permanent in the container ??? bcoz in my case i have to do /usr/sbin/sshd again and again