Automating Web Server Deployment with Jenkins and Ansible
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 apache2sudo 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.