Hello there, after reading this article, you will be able to configure the Apache Webserver on the top of Docker using Ansible.
So without any further delay, let’s get started, we will be using RHELv8.
Step by step tasks to be followed :
- Configure Docker
- 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
The system that you want to make Control Node install Ansible in it using the command :
pip3 install ansible
Now install openssh using the command :
yum install openssh
Now after installing ansible, just check it using the command :
Now It is clear that Ansible is installed perfectly.
After installing Ansible create an Inventory anywhere in the system, here I have created an inventory named ip.txt
Now we have to provide details of managed node in this file created, here I am Using RHEL8 OS as my Managed Node.
Here in “ ip.txt ” :
192.168.0.113 is IP of my Managed node
ansible_ssh_user : User you want to login in managed node
ansible_ssh_pass: provide the password of the above user
Now check the connectivity with Managed node using the command :
ansible all -m ping
If it shows a message in green color that means there is connectivity and you will see the message ping pong.
For running ansible command, we need inventory file which is expected to be at a specified path: “/etc/ansible/hosts”.
We can change its path using ansible config file (ansible.cfg file) in ansible workspace and define inventory file path there.
Now create yml file, here i have created file name docker.yml. This yml file is playbook where we write code in YAML.
The code in playbook is as below:
Now run the playbook using the command :
Here, If we see green color then it means that much code is skipped, if we orange then some changes are made and if we don’t see any red color in output then it means the playbook is executed successfully.
Now we can verify that docker is installed in Managed Node.
Also Docker repo got created in “ /etc/yum.repos.d ”.
We can also see that the container is launched.
Now check the IP of the container.
Docker service also started & is in Active (running) state.
Now finally the webpage is working well and is showing the content properly which we have written in the “ index.html file ”.
Thank you so much for reading & learning with me.