0% found this document useful (0 votes)
19 views

devops

Uploaded by

sivadjvijay12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

devops

Uploaded by

sivadjvijay12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 71

TABLE OF CONTENTS

Exp.No. Date Title of the Experiment PageNo. Marks Signature

1. Create Maven Build Pipeline in Azure

2. Run Regression Tests Using


Maven Build Pipeline in Azure

3. Install Jenkins in cloud

4.
Create CI Pipeline using Jenkins

5. Create CD Pipeline using Jenkins And


Deploy In Cloud

6. Create an Ansible Playbook for a Simple


Web Application Infrastructure

7. Build A Simple Application Using Gradle

8. Install Ansible and Configure Ansible Roles


And to Write Playbooks
EX NO: 1 Create Maven Build Pipeline in Azure
DATE:

AIM
To build a maven build pipeline in Azure.

PROCEDURE
STEP1: Create an account on the Azure DevOps website.
Goto https://azure.microsoft.com/en-in/products/devops/website and sign in using a GitHub
account.

Create a new organization with a suitable name of your choice. Here dhineshkumar1729 is the
organization name.
Create a new project named DevOps in private mode.

STEP2: Installing Intelli JIDEA


Download Intelli JIdea from https://www.jetbrains.com/idea/download/?section=linux and
activate a free trial for 30 days or through the following command.
$sudo snap install intellij-idea-community--community
Open the IDE using the below command in the terminal.
$intellij-idea-community
Java is a pre-requisite for using this IDE
STEP3: Create a new Maven project using the IDE.

Create a project by clicking on the New Project option, choose an appropriate name and select
the following features as mentioned in the image (Build system: Maven and Language: Java)

1.A sample code has been generated. Now press ALT+F12 to open a terminal inside the IDE.

STEP4: Install GIT and configure it

Check whether git is installed using the following command.


$git-version
Install git using
$sudo apt install git
Once git has been installed execute the following commands one by one.
$git init
$git add.
$git commit-m “First Commit”
$git branch-M main

Configure git using the below commands


$gitconfig—global user.name “Your Name”
$gitconfig—global user. Email “Your_Email_ID”

Gotohttps://github.comsigninwithyouraccountandcreateanewprivaterepositorywith the same


name as your maven project.

Copy the SSH URL for the created repository.


Now go back to IDE ’s terminal and execute the following commands
[email protected]
(press ENTER for all questions)
$cat~/.ssh/id_rsa.pub (copy the printed SSH key)
Now go to the SSH and GPG section in the Git Hub settings option.
$gitpush--set-up stream origin main(Type YES for prompted question)
$git remote set- url origin [email protected]:dk172923/sample.git
(Here,[email protected]:dk172923/sample. It is the remote URL to use SSH dk172923 – GitHub
ID
Choose a suitable name and paste the SSH key into the provided space.
Click on the New SSH key button.
Nowfinallyrunthepushcommandstopushthecodetotheremoterepositoryfromthe local repository.
Now get back to the IDE ’s terminal and type the following command
sample. git –repository name)
$ gitpush
The code has been successfully pushed to the remote repository.
STEP5: Create a pipeline for the created maven repository.
Click on Pipelines on the left pane of the Azure DevOps website.

Click on the Create Pipe line button.


Choose the GitHub YAML option.

Select the created repository “sample” from the available repositories.


Give permissions if prompted to do so and sign in to your GitHub account if needed.
Choose Maven Pipe line from the given options.
AYAML file is automatically created based on the configuration details found in the pom.xml
file in the repository.

Press the Save and Run button.


Create a commit message and press the run button again.
Click on the created Job from the Job stable
A successful job completion would be like this.

RESULT
Thus, a maven build pipeline has been created using Azure
EX NO: 2 Run Regression Tests Using Maven Build Pipeline
DATE: in Azure
AIM
To run regression tests using the Maven build pipeline in Azure.

PROCEDURE

STEP1 : Create a new maven project in Intelli JIDEAIDE.


Create a project with Regression Testing as its name.
Choose the Maven build system and available JDK version.
Select the Create Git Repository option.

Wait for some time until the indexes of the project have been updated.
Add the following snippet of code into pom.xml
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>

Once the changes have been made click on the referred button to update the changes made to
pom.xml or for simplicity just press CTRL + SHIFT + O

Now, inside the java folder on the Test directory create a package named org.example (Right
click on java folder inside the Test directory choose Newand select package)
Right-click on the package and create a new class named Main Test

Paste the following into the MainTest.javafile package org.example;


importorg.junit.Test;
import java.io.ByteArrayOutputStream; import java.io.PrintStream;
import static org.junit.Assert.assertEquals; public class Main Test {
@Test
Public void test MainMethod(){
// Redirect standard output to capture console output ByteArrayOutputStream outContent = new
ByteArrayOutputStream(); System.setOut(new PrintStream(outContent));

// Call the main method Main.main(newString[]{});

// Check if "Hello and welcome!" was printedassertEquals("Hello and welcome!",


outContent.toString().trim());

// Reset standard output System.setOut(System.out);


}
}
STEP2:Create a GitHub repository
Create a private repository with Regression Testing as its name.

Execute the following commands in the terminal of IntelliJIDEA

$gitinit
$gitadd.
$gitcommit-m“regression”
$gitbranch-Mmain
$gitremoteaddoriginYOUR_REPOSITORY_LINK
$gitpush-uoriginmain

NOTE:YOUR_REPOSITORY_LINK must contain either the HTTPS or SSH link to your


respective GitHub repository.
The Main Test class can be executed by Right-Clicking on the class from the project structure
and choosing Run ‘MainTest’

The following can be achieved on the Run tab.

STEP3:Create an Azure Pipeline


Open the Azure DevOps site
Click on existing project DevOps and choose Pipelines from the left pane.
Click on the New Pipeline button on the right.
Choose GitHub from the list.
Select the repository for Regression Testing.

If prompted for permission then select Approve and Install on GitHub website.

Configure the pipeline by choosing Maven


On the next page an azure-pipeline. Yml file is generated automatically. Replace this file with
the following code

#Maven
#BuildyourJavaprojectandruntestswithApacheMaven.
#Add steps that analyze code, save build artifacts, deploy ,and more:
#https://docs.microsoft.com/azure/devops/pipelines/languages/java

trigger:
-main

pool:
vmImage:'ubuntu-latest'

steps:
task: Maven@3 inputs:
mavenPomFile: 'pom.xml' mavenOptions: '-Xmx3072m'javaHomeOption:
'JDKVersion'jdkVersionOption: '11' jdkArchitectureOption: 'x64' goals: 'clean test'

task:PublishTestResults@2 inputs:
test ResultsFiles:'**/surefire-reports/TEST-*.xml'testRunTitle: 'JUnit Test Results'

Click on the Save and Run button to commit the changes and execute the pipeline.
The following results can be obtained on the output page.

From the test results tab it can be found that the tests passed.

RESULT
Thus, regression tests have been run using the Maven Build Pipeline in Azure.
EX NO: 3 Install Jenkins in Cloud
DATE:

AIM
To install Jenkins in the cloud(AWS).
PROCEDURE
STEP1:Create an AWS account
Go to https://aws.amazon.com/ and create an AWS Account.

Provide a root email ID and username for the user.


After Email verification setup your password.

Complete the sign-up process by providing additional information.


Provide the debit card information for the identity verification process. A charge of 2 rupees will
be debited.

Confirm your identity by providing the PAN card number associated with the name of the user.
Verify the phone number and perform a security check.

Select Basic Support as the plan since it is free of charge.


The AWS account has been successfully created and verified. Now click on Go to the Aws
Management Console button.

Sign in as a Root user by providing the appropriate email address and password.
STEP2: Create an EC2 instance.
Search EC2 in the search bar and choose EC2 from the services tab.

Click on the Launch Instance button.


Provide a name for the instance for example Jenkins Demo and choose Ubuntu as the operating
system.

Create a new keypair if you haven’t create done yet.


Give a suit able name for the key pair, select the key parity as RSA and click on the
Create key pair button at the bottom.

In the Network Settings tab select the following options.


Allow HTTPS traffic from the internet
Allow HTTP traffic from the internet
Wait while the instance is being launched. It may take sometime.

Select the Jenkins Demo instance and click on the Connect button.
Click on the Security tab and choose the Security Groups option.

Click on the Edit In bound Rules button.


Click on Add rule at the left bottom, enter the port range as 8080 and choose 0.0.0.0/0

Click on the Connect but to at the bottom after choosing Connect using EC2 Instance Connect.
A terminal is opened on a new tab in the same browser.

STEP3: Installing Jenkins on the instance.


Execute the following commands on the terminal to update the OS.
$clear
$sudo apt update
Execute the following command to install Jenkins.

$sudowget-O/usr/share/keyrings/jenkins-keyring.asc\
https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key

$echodeb[signed-by=/usr/share/keyrings/jenkins-keyring.asc]\ https://pkg.jenkins.io/debian-
stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list>/dev/null

$sudoapt-getupdate

$sudoapt-getinstallfontconfigopenjdk-17-jre

$sudoapt-getinstallJenkins

These commands canal so be found at https://pkg.jenkins.io/debian-stable/forDebian releases.

The following commands will start Jenkins.

$sudosystemctlstartJenkins
$sudosystemctlenableJenkins
$sudosystemctl status Jenkins

Copy the public IP address found below the terminal and copy the address. Open a new tab, paste
the IP address and add :8080 at the last.

Example:51.20.64.160:8080
STEP4: Configuring Jenkins
Jenkins will be initially locked. The password will be located at the location provided on the
screen. Copy it.
Go back to the terminal and execute
$sudocat/var/lib/Jenkins/secrets/initial Admin Password
Copy the password from the terminal, paste it on the Jenkins webpage and press Continue.

Select Installed suggested plugins to install the most used plugins in Jenkins.
The installation will take some time to complete.

Create a user login on the next page. Provide the necessary information and press
Save and Continue.
Check whether the Jenkins URL is the same as the one mentioned in the address bar and press
Save and Finish.

Now Jenkins has been successfully configured on the cloud. Click on Start using Jenkins to work
with it.
TheJenkinswebpagewouldlooklikebelow.Jobscanbebuilthere.

RESULT:
Thus, Jenkins has been install done the cloud.

Downloaded by Karthick karuppiah ([email protected])


EX NO: 4 Create CI Pipeline using Jenkins
DATE:

AIM:
To create a CI pipeline using Jenkins.

PROCEDURE:
STEP1:Click and open this GitHub repository(https://github.com/benc-uk/python-demoapp.git). And
also click fork to make the changes in your own account.
(Note: The username and password in GitHub, Jenkins and Docker Hub website should be the same.)

STEP2: Now you have moved into your own GitHub account.

Downloaded by Karthick karuppiah ([email protected])


STEP3:Click the src directory, choose requirements. Txt and you will be able to seethe below code.

STEP4: Now, you can make the below changes in the code.

Downloaded by Karthick karuppiah ([email protected])


STEP5:ClickbuilddirectoryandchooseDockerfileand youwillbeabletoseethebelow code.

STEP6:Replace the above link with your own GitHub repository link.

Downloaded by Karthick karuppiah ([email protected])


STEP7:Click on make file, and you will be able to see the below code.

STEP8:ReplacetheabovenameinthecodewithyourownGitHubnameandalso replace the ghcr.io with


docker.io.

Downloaded by Karthick karuppiah ([email protected])


STEP9: OpentheJenkinspage,andclickonthenewitemthatispresentinthedashboard.

STEP10: Now Enter the item name and select pipeline, then click on OK.

STEP11:Click>Install_tools>Configure>Pipeline. In the definition section of Pipeline, Choose


Pipeline script and the script area will be visible in which you will type the below code.

Downloaded by Karthick karuppiah ([email protected])


pipeline { agentany
stages{
stage('PythonVersion'){ steps {
sh"sudoapt update"
sh"sudoapt-yupgrade"
sh"sudoaptinstallpython3.10-venv-y" sh "python3 -v"
}
}
stage('DockerVersion'){ steps{
sh"docker-v"
}
}
stage('InstallMake'){ steps{
sh"sudoaptinstallmake-y"
sh"sudoaptinstallmake-guile-y"
}
}
}
}
Now, Click on Save.

Downloaded by Karthick karuppiah ([email protected])


STEP12:Click on the Install_tools and select the build now.

STEP13: In the Build history section, click on the builds then you will able to seethe console output
as ‘FINISHED: SUCCESS’. Now The Pipeline is built.

Downloaded by Karthick karuppiah ([email protected])


STEP 14: Click > Dashboard > Manage Jenkins> Plugins. In Plugins, Select Available Plugins.
Here, search for docker and select the associated plugins (Docker, docker pipeline, docker build step,
Cloud Bees Docker Build and Publish) then install it.

Downloaded by Karthick karuppiah ([email protected])


STEP15: In Download progress, you will be able to see the set of plugins that were installed.

STEP16:Run the following commands in the AWS ubuntu terminal.


To Create the Docker Group:
$sudogroupadddocker

To Add the Jenkins User to the Docker Group:


$sudousermod-aGdockerjenkins
(Replace‘jenkins’withtheactualusernameoftheJenkinsuser)

To Verify the Group Membership:


$groupsJenkins
Toinstallthedocker:
$sudoaptinstalldocker.io

Torestartjenkins:
$sudosystemctlrestart Jenkins

Downloaded by Karthick karuppiah ([email protected])


STEP17:Click>Manage Jenkins>Tools .Scroll for the docker section and perform the following
actions in the image.

STEP18:Open Browser and search for docker hub ,then create an account in docker hub.

Downloaded by Karthick karuppiah ([email protected])


STEP19:Click on the new item in the Jenkins dashboard. Now Enter the item name and select
pipeline, then click on OK.

Downloaded by Karthick karuppiah ([email protected])


STEP20:Click>dashboard>python-webapp>configure. In the general section, select
‘Discard oldbuilds’andsetthemaxofbuildsto1.

STEP21:Scroll down for Pipeline. In the Script area, run the below code. pipeline {
agentany stages{
stage('GitCheckout'){ steps {
gitchangelog:false,poll:false,url:’’ }
}
stage('DockerBuild'){ steps {
sh"makeimage"
}
}
stage('DockerPush'){ steps {
script{
withDockerRegistry(credentialsId:’‘,toolName:’‘){ sh "make push"
}
}
}
}
}
}

Downloaded by Karthick karuppiah ([email protected])


STEP22:Click on pipeline syntax and Select the Snippet generator
In the Sample step, choose the git:Git.

Paste your GitHub URL in the URL section.


Type as ‘main’ in Branch and deselect the options.

Downloaded by Karthick karuppiah ([email protected])


Click on Generate pipeline script.

Downloaded by Karthick karuppiah ([email protected])


STEP23: InStep21, paste the above generator pipeline script in the URL portion of the code.

STEP24: Again Click on pipe line and select the Snippet generator.

In the Sample step, choose the below option.

Make the Registry Credentials null and click Jenkins.

Downloaded by Karthick karuppiah ([email protected])


Now, provide the username and password (GitHub)and click save.

The Credentials will have been added in the Registry Credentials section select the docker below,
then click on Generate pipeline script.

Downloaded by Karthick karuppiah ([email protected])


STEP25 : In Step21 ,paste the above generator pipeline script in the Credentials ID and tool name
portion of the code.

Downloaded by Karthick karuppiah ([email protected])


STEP26: Click>dashboard>python-webapp> build now.

STEP27: Now CI Pipeline has been built Successfully.

RESULT:
Thus, the CI Pipeline has been successfully created.

Downloaded by Karthick karuppiah ([email protected])


EX NO: 5 Create CD Pipeline using Jenkins and Deploy in Cloud
DATE:

AIM:
To create a CD pipeline in Jenkins and deploy it in the Cloud.

PROCEDURE:
STEP1: Click Repositories> python demo app>General .There, you will be able to see a command
under Docker commands. Copy that command.

STEP2 :Now, go to your Git Hub account .Scroll down to Containers and copy the command again
for future use.

Downloaded by Karthick karuppiah ([email protected])


STEP3: Now add the code (combination of the above commands)below to the code through which
the CI Pipeline was built.

stage('Docker Deploy'){
steps { script{
with Docker Registry (credentials Id: 'dbc54abf-de2b-42b8-a0d2-f5539c9b8997', tool Name:
'docker') {
sh" docker images"
sh" docker run-d--rm-it-p80:5000jayashriashokkumar28112003/python-
webapp: latest"
}
}
}
}

Downloaded by Karthick karuppiah ([email protected])


STEP4: Click on Dashboard>python-webapp>Build Now

STEP5: To access the Python web app copy and paste the public IP of the AWS instance and include
port 5000 at the end of it. (For example: 41.204.111.57:5000)

RESULT:
Thus, the CD pipeline has been successfully created in Jenkins and deployed in the
Cloud.

Downloaded by Karthick karuppiah ([email protected])


EX NO: 6 Create an Ansible Playbook for a Simple Web
DATE: Application Infrastructure

AIM
To Create an Ansible Playbook for a simple web application infra structure.

PROCEDURE

STEP1: Create a directory named ansible-practice1 and then navigate in to that directory with the cd
command.

The following commands are used to create a directory,


$cd~
$mkdiransible-practice1
$cdansible-practice1

To add content to playbook use the following commands,


$nano playbook01.yml

STEP2: Now create a playbook that contains the following content to be executed. The content to be
added in the playbook (playbook01.yml),

---
-hosts: local host tasks:
-name: Print message debug:
msg: Hello Ansible World

NOTE: The host name in the content must be changed to localhost.

Downloaded by Karthick karuppiah ([email protected])


STEP 3: Run ansible-playbook with the same connection arguments, use an inventory file named
inventory and the Sammy user to connect to the remote server. The command to run the ansible
playbook,

$ansible-playbook-iinventoryplaybook-01.yml-usammy

RESULT:
Thus, creating and executing an ansible playbook for a simple web application infrastructure has
been executed successfully.

Downloaded by Karthick karuppiah ([email protected])


EX NO: 7 Build A Simple Application Using Gradle
DATE:
AIM
To build a simple application using Gradle.

PROCEDURE
Step 1: Create directory: `java application`. Step 2: Change to directory: `java application`. Step 3:
Run `gradle init` command.
Step4:Select project type(application).
Step5:Choose implementation language(Java).
Step6:Select build script language(Groovy).
Step7:Choose testing framework(JUnit4).
Step8:Enter project name.
Step9:Enter source package.

Install gradle using the following command

Create a directory named java_application and change directory:

Downloaded by Karthick karuppiah ([email protected])


Run the gradle init command to create a new Gradle project

Select the project type (application, library, etc.) by typing `2` and pressing Enter for an application.

Choose the implementation language (Java,Kotlin,etc.)bytyping`3`andpressing Enter for Java.

Downloaded by Karthick karuppiah ([email protected])


Select the default build script language (GroovyorKotlin)bytyping`1`andpressing Enter for
Groovy.

Choose the testing frame work (JUnit4, TestNG ,etc.)ifprompted.ThedefaultisJunit4

Enter the project name when prompted (default is the directory name) & Enter the source package
when prompted (default is the directory name).

Downloaded by Karthick karuppiah ([email protected])


OUTPUT

Downloaded by Karthick karuppiah ([email protected])


RESULT
Thus, the Java application was successfully created using Gradle.

Downloaded by Karthick karuppiah ([email protected])


EX NO: 8 Install Ansible and Configure Ansible Roles and to
DATE: Write Playbooks

AIM
To install Ansible, configure Ansible roles and write playbooks.

PROCEDURE

Step1: Refresh your system’s package index so that it is aware of the packages available. Run
the following command,

$sudo apt update

Step2:The Ansible package and its dependencies are available in the default package
repositories to install the latest Ansible version, add its ppa repository.

$sudo apt upgrade


$sudo apt install-y software-properties-common
$sudo add-apt-repository--yes—update ppa: ansible/ansible
Step3: Now install the ansible latest version using the command,
$sudo apt install ansible

Now we are going to navigate the directory path to,


$cd/etc/ansible/
Then , we will check the latest version of the ansible by,
$ansible–version

Step4:To check the list of directories and files present in the ansible ,run the command as,
$ls–la
Then check the host file by,
$sudo nano hosts

Step5:Create an ansible role from scratch and run ansible-galaxy command.


$ansible-galaxy init my-role
$ ls

To view the role directory structure ,run the tree command followed by the role name.
Step6: Create three ansible roles as follows:
The prerequisites role–Install git.
The post gre sql role – Installs postgre sql service. The apache role–Installs the Apache
webserver. Use the following commands to create the above,

$sudoansible -galaxyinit prerequisites


$sudoansible-galaxyinitPostgreSQL
$sudoansible-galaxyinitapache
$ ls

Step7: Define each role that you have created. To achieve this, you need to edit the main. yml
file located in the ‘tasks’ folder for each role.
First for prerequisites,

$cdprerequisites/tasks/
Then edit the main. Yml file by the command,
$sudo nano main.yml

Then add the content to this main. Yml file as # tasks file for prerequisites
-name: Install git apt:
name: git state: present
update_cache: yes
Next for PostgreSQL,
$cdPostgreSQL/tasks/
$sudo nano main .yml
Then add the content to this main. Yml file as, # tasks file for PostgreSQL
-name: Install PostgreSQL apt:
name: post gresql state: present update_cache: yes
-name: Start Post gre SQL service systemd:
Name :postgre sql state: started enabled: yes
Finally for the apache web server,
$cdapache/tasks/

$sudo nano main .yml


Then add the content to this main. Yml file as, # tasks file for apache
-name: install Apache web server apt:
name: apache2 state: present update_cache:yes

Lastly, we are going to create a play book file called stack. Yml and call the roles by the
command,
$sudo nano stack .yml
Then add the content to this main. Yml file as
hosts: localhost become: true roles:
prerequisites
PostgreSQL
apache
Step8: Ensure that our roles are working as expected, and run the ansible playbook. Run the
following command,
$sudoansible-playbook stack.yml

Then check the versions to ensure that the packages were installed successfully,
$git--version
$ apachectl –v
RESULT
Thus, installing ansible ,configuring ansible roles and writing playbooks have been executed
successfully.

You might also like