Arth Task-10
About ANSIBLE.
Ansible is a software tool that provides simple but powerful automation for cross-platform computer support. 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 Docker?
Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and deploy it as one package. By doing so, thanks to the container, the developer can rest assured that the application will run on any other Linux machine regardless of any customized settings that the machine might have that could differ from the machine used for writing and testing the code.
TASK DESCRIPTION:
Write an Ansible PlayBook that does the following operations in the managed nodes:
→Configure Docker
→Start and enable Docker services
→Pull the httpd server image from the Docker Hub
→Run the docker container and expose it to the public
→Copy the html code in /var/www/html directory
and start the webserver
Configuring Web Server over the Docker Container Using Ansible.
- Install ansible using this command on your Linux os.
pip3 install ansible
- Creating inventory for ansible.
- Providing inventory location to the ansible configuration file.
- Check whether you can connect to the host or not.
- Creating a playbook.
- Configuring docker repo on target node(s)
- Installing docker-ce software using command module of Ansible
- Started the docker services and permanently enabled them.
- Installed docker-py library using pip command which was required by ansible.
- Creating a directory where container volume is to be mounted — as docker container volume will be mounted on this folder (named as Task10) during the installation of the docker container. NOTE: you can also create a folder inside the/var/www/html directory and mount that container volume onto that folder
- Copied a web page(x.html) from the Controller node to the target node.
7. Pull an httpd image- using docker_image module
8. Launched a container name as “docker_web” — using docker_container module . Image used — httpd:latest, exposed port -80, volume mounted onto the directory /web.
9. Started the above-created container.
- Run this Playbook
ansible-playbook dockerconf.yml
NOTE: Whenever you run/execute a playbook -> the msg in Green color signifies that nothing changes were made in the target nodes. This means that your requirement already existed. Msg in Yellow color shows that changes were made in the target node, which means that the target node didn’t have whatever your requirement was and ansible completed that requirement for you.
Hence this shows that my playbook worked extremely well and all the requirements were fulfilled.
- Proof that the target node was configured according to my requirement
a) Docker repository configured.
b) Docker-ce software installed.
c) Started and enabled docker services.
d) Downloaded httpd image.
e) Container named as web container is running and with its port 80 linked to port 8888 of base VM.
f) This below is the web page deployed from the controller node over to this target node inside the task10 directory.
- Browsing this webpage
http://172.10.0.2/x.html
HENCE THE WEBPAGE IS VISIBLE OVER THE BROWSER.