Start and enable Docker services
Pull the httpd server image from the Docker Hub
Run the httpd container and expose it to the public
Copy the html code in /var/www/html directory and start the web server
Install the ansible program on the rhel8 os using pip3 install ansible and then configure it by creating the ansible.cfg file and creating the inventory in it. After this check the network connectivity between a different manager nodes using the ping module.
In my manager node of ip 192.168.43.28, i dont have installed any docker-ce software and also their is no repo file for docker.
So in the playbook first we write the code to make a repository for docker file and then we use the yum to install the docker-ce program.
we can also use the yum module to install the docker-ce package but in rhel8 we can’t directly install this package we need ‘ — — nobest’ option to install it, which is not available in the yum module so we need to install the package using command module as shown. Their is one more catch for installing the docker-ce using the package module by giving the complete package name we can install it. But it can work only for the rhel8 system maybe if their is a requirement to install it on a different OS or different rhel version then it might give some error. So i have used the command module for this.
After installing the docker-ce package inside the rhel8 , we now install the python36 software and docker library because the ansible program has been created using the python language and to connect the docker on a different operating system we need to install these libraries in all those different machines.
Then we move to start the docker services using the ansible service module and after starting the service we first download the httpd image.
Now after pulling the image we start the container using the docker_container module.
Here we have first exposed the port 80 as the webserver runs on this port and the used 4243 port (for PAT) so that anyone can come on 4243 port and can be redirected to the running webserver.
Here while launching the container we have to mount a folder to the working directory file of the image. As for now we can’t directly copy the file into a running container. And then we have copied our html files from the controller node to this mounted folder.
After running ansible-playbook pb1.yml command we can get the desired results.
Here I have tried to configure the httpd server on the top of rhel 8 server and it works as we can use the command module to run multiple commands on the base os . But using the command modules have its own demerits. Maybe if the OS is other than redhat than it might give some problem. For now i dont have any knowledge if their is different module to directly connect through the container. In future if i found something useful regarding this i will definitely post it about this.
For now all the code is in my github repository. you can get it from their.
Github URL: https://github.com/akshat-crypto/RH294_task1.git
LinkedIN profile: https://www.linkedin.com/in/akshat-soni-011b461a6