Ansible playbook that will retrieve new Container IP and update the inventory so that further Configuration of Webserver could be done inside that.
Pratik Kohad ????
SIH Grand Finalist 2020 || MLops || ARTH Ambassador and Learner at LinuxWorld Informatics Pvt. Ltd
?? Task Description ??
?? 14.2 Further in ARTH — Task 10 has to create an Ansible playbook that will retrieve the new Container IP and update the inventory. So that further Configuration of the Web server could be done inside that Container.
This is an important article on the ansible-playbook and configuration of the Web server inside that Container. This article also explains how to automate the task given.
Task 10: https://cutt.ly/QQTzoX6
Before moving to the task let us see some important concepts:
What is ansible???
In simple words, Ansible is an?open-source IT automation engine, which can remove drudgery from your work life, and will also dramatically?improve the scalability, consistency, and reliability of your IT environment.?It is primarily intended for IT professionals, who use it for application deployment, updates on workstations and servers, cloud provisioning, configuration management, intra-service orchestration, and nearly anything a systems administrator does on a weekly or daily basis. Ansible doesn't depend on agent software and has no additional security infrastructure, so it's easy to deploy.
What is an ansible-playbook?
An?Ansible?playbook?is a blueprint of automation tasks—which are complex IT actions executed with limited or no human involvement.?Ansible playbooks?are executed on a set, group, or classification of hosts, which together make up an?Ansible?inventory.
What is dynamic inventory?
The?dynamic inventory?script can do anything to get the data (call an external API, pull information from a database or file, etc.), and?Ansible?will use it as an?inventory?source as long as it returns a JSON structure like the one above when the script is called with the --list.
What is docker?
Docker?is an open platform for developing, shipping, and running applications.?Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With?Docker, you can manage your infrastructure in the same ways you manage your applications. And it also helps to install and the boot in just seconds.
What is a container?
A?Docker container?image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries, and settings.
So, here we start with our task:-
Step 1:?Python3 should be installed on your controller node in order to install an ansible.
In my case, python3 is already installed. we can check its version by using the command:
python3 --version
Step 2:?Now, let's install ansible using the command:
pip3 install ansible
Step 3: Initially the inventory file is empty
vim /etc/ansible/ansible.cfg
Step 4: Ansible Playbook for container setup and auto-updating of the inventory file
vim docker.yml
Let's check the index.html file
Step 5: Now let's check the code is correct or not.
ansible-playbook --syntax-check docker.yml
Step 6: let's Run the Playbooks
First, let’s set up the container and set up the inventory file
ansible-playbook docker.yml
Step 7: Inventory file is dynamically updated
Step 8: Now let's c Docker Service started and enabled in the system
systemctl status docker
Here I have used some modules of Ansible which are as follows:
?yum_repository?( For creating Docker Repo in Yum Configuration file in our Slave Node?
Package:?For installing the docker software),?
service?( For starting the Service of Docker),?
pip?(To install the Docker Python),?
docker_image?( For downloading the docker image from the Docker Hub),?
copy?(To copy my web page from Master (controller) to Slave(Target),?
docker_container?(For starting the docker webserver container).
Step 9: Let us see the output using the curl command
curl https://172.17.0.5/index.html
Step 9: Let's use the docker ps command to see it is launch or not.
Hence, we have successfully completed the task.
Github URL: https://github.com/pratikkprojecthub/ansibleprojects.git
Thanks for Reading the article !!! ????????
Hope you might find this article helpful!!!!
You can appreciate the article by giving it a like and posting comments about your feedback.
Feel free to ask any queries. Don’t forget to share this article with your colleagues.??