Deploying Web Server on Docker Using Ansible Playbook

Kriti Dubey
3 min readMar 21, 2021

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:-

  1. Configure Docker
  2. Start and enable Docker Services
  3. Pull the httpd server image from Docker Hub
  4. 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😊

--

--