In this blog, we will explore the CI/CD process using Jenkins and Ansible. We will deploy the sample java application using Ansible on the tomcat servers. At last,this process will help us in achieving continuous integration and continuous deployment for your application.
We have make the project on master node
Jenkins is a javabased program. So to install Jenkins we have to first install Java-11, then Jenkins.
Install java:
\=============================
sudo apt install default-jre -y
Install jenkins:
curl -fsSL pkg.jenkins.io/debian-stable/jenkins.io-202.. | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] pkg.jenkins.io/debian-stable binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins -y
sudo systemctl start Jenkins
Now we have to move to lab desktop to visit Jenkins official page “localhost8080”.
Jenkins set up
So here comes our Jenkins
Here Jenkins is ready to use now.
Now we have to set up Install Ansible plugins in Jenkins CI server.
we have to go to manage Jenkins.
Manage Jenkins--> plugins --> available plugins --> Search for plugin Ansible>> click on install without restart.
Now we have to configure ansible tools.
Configure ANsible tool in Jenkins
Manage Jenkins--> Configure Tools --> Scroll down to find Ansible --> Add ansible--> give name as myansible-->give path as /usr/bin
Playbook to install maven and docker
Now we are going to run the playbook
Here comes playbook running successfully
Now Playbook to build the java code and deploy the build code:
First we have to create a playbook called as playbookDeployment.yml
Playbook running successfully
Now both the playbooks are ready.
Now we have to create a github repo where we are going to place the playbooks.
Her we are going to make a inventory file also .
And weSo here we are going to github and creating a new repository.
will ask Jenkins to clone the repo and execute the playbooks.
Repository created
In the repository we will create a new file
First playbook we will mention here as playbookInstall.yml
Now we are going to add another file for playbookDeployment.yml
Now going to create a inventory file In inventory fil we create groups with their ip address.
Now we have to go to Jenkins to write down the code in order to run the playbooks
Now w are going to create pipeline
pipeline code =====
pipeline{
agent any
stages{
stage('clone the repo')
{
steps{
git branch: 'main', url: 'https://github.com/Biswaraj111/SL-CMAT-CEP1-Jenkins-Ansible.git'
}
}
stage('run playbook1')
{
steps{
ansiblePlaybook credentialsId: 'ansible', disableHostKeyChecking: true, installation: 'myansible', inventory: 'dev.inv', playbook: 'PlaybookInstall.yml'
}
]
stage('Run playbook Deployment')
{
steps{
ansiblePlaybook credentialsId: 'ansible', disableHostKeyChecking: true, installation: 'myansible', inventory: 'dev.inv', playbook: 'PlaybookDeployment.yml'
}
}
}
}