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

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

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 Start

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.

Code of Dockerfile

No alt text provided for this image

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

Lets check the ansible version installed on my controller node:

ansible --version
No alt text provided for this image

Initially inventory file is empty

cat /root/ip.txt

Configure ansible.cfg

vim /etc/ansible/ansible.cfg
No alt text provided for this image

Ansible Playbook :

vim docker.yml


No alt text provided for this image
vim docker-web.yml
No alt text provided for this image

dockerip.j2 file

No alt text provided for this image

Task14.html file

No alt text provided for this image

Now let’s run the Playbook

ansible-playbook docker.yml

No alt text provided for this image
No alt text provided for this image

Container is successfully launched with name Webos.

Inventory file dynamically updated

No alt text provided for this image

Check Docker Service started and enabled:

No alt text provided for this image

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

No alt text provided for this image

Done! 

Now checking webos container:

No alt text provided for this image

Now the webserver has been deployed on the docker container.

So Let’s check our webpage from the browser:

No alt text provided for this image

GitHub

Thank You



Aniket Khadye

Site Reliability Engineer at Crest data systems

4 年

Great work

回复

要查看或添加评论,请登录

Anudeep Nalla的更多文章

社区洞察

其他会员也浏览了