Automating Web Server Deployment with Jenkins and Ansible

Dheeren GaudDheeren Gaud
2 min read

In this blog, I am showcasing two small projects where I learned new things, such as how to execute an Ansible playbook, create a web server, and deploy my portfolio on a remote server using Ansible.

I Made 2 Projects

  • Ansible Job Execution

  • Deploying Portfolio on Apache Remote Server

In these two projects, I learned:

  • How to write a simple Ansible playbook

  • How to create a Jenkins user on a remote server

  • How to run an Ansible file from the host and Jenkins dashboard

  • Jenkins Ansible configuration


1. Ansible Job Execution

I created a remote and host setup on VirtualBox.
On the host, I have a Jenkins server where I installed the Ansible plugin and tried to access the remote server by pinging it from an Ansible playbook.

I configured Jenkins in my job.

I encountered a problem during execution. The issue was with the Ansible host, so I specified my host and username in the hosts file.

above image show anisble playbook path

The image above shows the Ansible playbook where I am simply pinging the server.

The image above shows the log after successfully building the job.


2. Deploying Portfolio on Apache Remote Server

This is a bit similar to the previous project, but here a few more things are added, like a web server.

  • Inside the playbook, I am copying the Git code from the workspace to the remote Apache server.

  • Then, in the playbook, I am restarting the web server.

above is play book code Before running this, you should install the Apache server on the remote server.
This command is for installing the Apache server.
sudo apt install apache2
sudo systemctl status apache2

The image above shows my Apache server running on the remote server.

When I was building this, I faced many problems, such as:

  • The Jenkins user didn't have sudo access, so I granted access through Ansible.

  • Granting sudo permission on the remote server.

These are some build failures I encountered, so I did the following:

On the remote server, add Jenkins to the sudo group:

On the Jenkins server, add an extra variable in the job.

password here is jenkins user password of remote server

by doing this i solve all the errors
here is Output log

and on remote server i ca access my portfolio

After this, I added SCM polling and email notifications to my job. So, whenever a commit happens, it automatically builds.

0
Subscribe to my newsletter

Read articles from Dheeren Gaud directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Dheeren Gaud
Dheeren Gaud

Hi, I'm Dheeren — currently pursuing my Bachelor's degree in Information Technology from Father Agnel College (FCRIT). I have a deep interest in web development, especially in the MERN stack, and have worked on several projects including MY-docs, Predictive Maintenance systems, a WhatsApp clone, and custom chatbot applications. Over time, I’ve developed strong skills in Java, data structures, and algorithms, and I’m always excited to solve complex problems through technology. Recently, I’ve become very interested in DevOps and am actively learning tools and technologies like Docker, Kubernetes, CI/CD pipelines, and cloud platforms to enhance my development and deployment workflows. I’ve also participated in national-level hackathons such as SIH, Terna, Kongsberg Maritime, and NIT Jalandhar, and was fortunate to achieve recognition in some of them. These experiences have helped shape my collaborative, problem-solving, and quick-learning mindset. Always open to learning, collaborating, and building impactful solutions!