Deploying Web Server on Docker Using Ansible Playbook
Step 1: Install Ansible
Command: pip3 install ansible
Step 2: Create an Inventory file
Add the managed node IP address, user name, password, and connection type in the inventory file.
Step 3: Configure Ansible
Create a directory using the command: mkdir /etc/ansible
add the inventory file location in the ansible configuration file: ansible.cfg and write host_key_checking=False to disable the ssh key.
Step 4: Check the Connectivity
Check the connectivity of the control node with managed nodes
Command: ansible all -m ping
Step 5: Write the code in the Playbook
Tasks:-
- Configure Docker
- Start and enable Docker Services
- Pull the httpd server image from Docker Hub
- Copy the HTML code in /var/www/html directory and start the web server
Step 6: Run the Playbook
Step 7: Check the Webserver
Check whether docker service is running or not using the command: systemctl status docker
Check whether port 8080 is running or not
Use Command: netstat -tnlp | grep 8080
It's working perfectly fine:)
😊Thank you for Reading😊