Ansible playbook that will retrieve new Container IP and dynamically update the inventory and Configure web-server inside that Docker Container
Anudeep Nalla
Opensource Contributer | Platform Engineer | EX-NPCI | RHCA Level III | OpenShift | CEPH | CK{S,A,AD} | 3x Microsoft Certified | AWS CSA | Rancher | Nirmata | DevOps | Ansible | Jenkins | DevSecOps | Kyverno | Rook-Ceph
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
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
Initially inventory file is empty
cat /root/ip.txt
Configure ansible.cfg
vim /etc/ansible/ansible.cfg
Ansible Playbook :
vim docker.yml
vim docker-web.yml
dockerip.j2 file
Task14.html file
Now let’s run the Playbook
ansible-playbook docker.yml
Container is successfully launched with name Webos.
Inventory file dynamically updated
Check Docker Service started and enabled:
Now we can run our docker-web.yml playbook to configure webserver inside container:
Done!
Now checking webos container:
Now the webserver has been deployed on the docker container.
So Let’s check our webpage from the browser:
GitHub
Site Reliability Engineer at Crest data systems
4 年Great work