Devops Lab Manual Final
Devops Lab Manual Final
RATHINAMANGALAM, CHENNAI-127.
CCS342 - DEVOPS
Name :
Reg. No :
Branch :
Year :
Semester :
Anna University∷Chennai
Regulation 2021
LABORATORY RECORD
Mr. /Ms. of
Record Mark:
VISION
MISSION
Adopting an efficient teaching learning process in concurrence with increasing industrial demands.
Ensuring technical proficiency, facilitating to pursue higher studies and carry out Research &
Development activities.
Developing problem solving and analytical skills with deep knowledge in thorough understanding
of basic sciences.
and Computer Science Engineering.
Infusing managerial and entrepreneurship skills to become ethical, socially responsible, and
competitive professionals.
1. Exhibit design and programming skills to build and automate business solutions using
cutting edge technologies
3. Ability to work effectively with various engineering fields as a team to design, build and
develop system applications.
2. Problem analysis: Identify, formulate, review research literature, and analyze complex engineering
problems reaching substantiated conclusions using first principles of mathematics, natural sciences,
and engineering sciences.
3. Design/development of solutions: Design solutions for complex engineering problems and design
system components or processes that meet the specified needs with appropriate consideration for the
public health and safety, and the cultural, societal, and environmental considerations.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities with
an understanding of the limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the
professional engineering practice.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader
in diverse teams, and in multidisciplinary settings.
11. Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one‘s own work, as a member and
leader in a team, to manage projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to engage
in independent and life-long learning in the broadest context of technological change
COURSE OUTCOMES
CO1: Understand different actions performed through Version control tools like Git.
CO2: Perform Continuous Integration and Continuous Testing and Continuous Deployment using
Jenkins by building and automating test cases using Maven & Gradle.
CO3: Ability to Perform Automated Continuous Deployment.
CO4: Ability to do configuration management using Ansible.
CO5: Understand to leverage Cloud-based DevOps tools using Azure DevOps.
TABLE OF CONTENTS
Exp. No. Date Title of the Experiment Page No. Marks Signature
Date:
AIM
To build a maven build pipeline in Azure.
PROCEDURE
1. 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 andLanguage:
Java)
1. A sample code has been generated. Now press ALT + F12 to open a terminal insidethe
IDE.
3.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
1. Go to https://github.com sign in with your account and create a new private repositorywith
the same name as your maven project.
RESULT
Thus, a maven build pipeline has been created using Azure.
AIM
PROCEDURE
4. Wait for some time until the indexes of the project have been updated.
5. 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>
6. 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
7. 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 New and
select package)
$ git init
$ git add .
$ git commit -m “regression”
$ git branch -M main
$ git remote add origin YOUR_REPOSITORY_LINK
$ git push -u origin main
3. The MainTest class can be executed by Right-Clicking on the class from the project
structure and choosing Run ‘MainTest’
2. Click on existing project DevOps and choose Pipelines from the left pane.
3. Click on the New Pipeline button on the right.
4. Choose GitHub from the list.
5. Select the repository for RegressionTesting.
6. If prompted for permission then select Approve and Install on GitHub website.
# Maven
# Build your Java project and run tests with Apache Maven.
# 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:
testResultsFiles: '**/surefire-reports/TEST-*.xml'
testRunTitle: 'JUnit Test Results'
9. Click on the Save and Run button to commit the changes and execute the pipeline.
11. 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.
AIM
PROCEDURE
5. Provide the debit card information for the identity verification process. A charge of 2
rupees will be debited.
6. Confirm your identity by providing the PAN card number associated with the name of
the user.
9. The AWS account has been successfully created and verified. Now click on Go to the
Aws Management Console button.
10. Sign in as a Root user by providing the appropriate email address and password.
1. Search EC2 in the search bar and choose EC2 from the services tab.
3. Provide a name for the instance for example Jenkins Demo and choose Ubuntu as the
operating system.
5. Give a suitable name for the key pair, select the key pair type as RSA and click on the
Create key pair button at the bottom.
7. Wait while the instance is being launched. It may take some time.
8. Select the Jenkins Demo instance and click on the Connect button.
9. Click on the Security tab and choose the Security Groups option.
11. Click on Add rule at the left bottom, enter the port range as 8080 and choose
0.0.0.0/0
12. Click on the Connect button at the bottom after choosing Connect using EC2
Instance Connect.
4. 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
1. Jenkins will be initially locked. The password will be located at the location provided
on the screen. Copy it.
2. Go back to the terminal and execute
$ sudo cat /var/lib/Jenkins/secrets/initialAdminPassword
3. Copy the password from the terminal, paste it on the Jenkins webpage and press
Continue.
4. Select Installed suggested plugins to install the most used plugins in Jenkins.
6. Create a user login on the next page. Provide the necessary information and press
Save and Continue.
7. Check whether the Jenkins URL is the same as the one mentioned in the address bar
and press Save and Finish.
8. Now Jenkins has been successfully configured on the cloud. Click on Start using
Jenkins to work with it.
9. The Jenkins web page would look like below. Jobs can be built here.
RESULT:
Date:
AIM:
To create a CI pipeline using Jenkins.
PROCEDURE:
STEP 2: Now you have moved into your own GitHub account.
STEP 3: Click the src directory, choose requirements.txt and you will be able to see the
below code.
STEP 4: Now, you can make the below changes in the code.
STEP 5: Click build directory and choose Dockerfile and you will be able to see the below
code.
STEP 6: Replace the above link with your own GitHub repository link.
STEP 7: Click on makefile, and you will be able to see the below code.
STEP 8: Replace the above name in the code with your own GitHub name and also replace
the ghcr.io with docker.io.
STEP 9: Open the Jenkins page, and click on the new item that is present in the dashboard.
STEP 10: Now Enter the item name and select pipeline, then click on OK.
STEP 11: 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.
pipeline {
agent any
stages {
stage('Python Version') {
steps {
sh "sudo apt update"
sh "sudo apt -y upgrade"
sh "sudo apt install python3.10-venv -y"
sh "python3 -v"
}
}
stage('Docker Version'){
steps{
sh "docker -v"
}
}
stage('Install Make'){
steps{
sh "sudo apt install make -y"
sh "sudo apt install make-guile -y"
}
}
}
}
STEP 12: Click on the Install_tools and select the build now.
STEP 13: In the Build history section, click on the builds then you will able to see the
console output as ‘FINISHED: SUCCESS’. Now The Pipeline is built.
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, CloudBees Docker Build and Publish) then install it.
STEP 15: In Download progress, you will be able to see the set of plugins that were
installed.
STEP 16: Run the following commands in the AWS ubuntu terminal.
1. To Create the Docker Group:
$sudo groupadd docker
STEP 17: Click > Manage Jenkins> Tools. Scroll for the docker section and perform the
following actions in the image.
STEP 18: Open Browser and search for docker hub, then create an account in docker hub.
STEP 19: Click on the new item in the Jenkins dashboard. Now Enter the item name and
select pipeline, then click on OK.
STEP 20: Click > dashboard > python-webapp > configure. In the general section, select
‘Discard old builds’ and set the max of builds to 1.
STEP 21: Scroll down for Pipeline. In the Script area, run the below code.
pipeline {
agent any
stages {
stage('Git Checkout') {
steps {
git changelog: false, poll: false, url:’’ }
}
stage('Docker Build') {
steps {
sh "make image"
}
}
stage('Docker Push') {
steps {
script{
withDockerRegistry(credentialsId:’ ‘, toolName:’ ‘ ) {
sh "make push"
}
}
}
}
}
}
STEP 22: Click on pipeline syntax and Select the Snippet generator
STEP 23: In Step 21, paste the above generator pipeline script in the URL portion of the
code.
STEP 24: Again Click on pipeline and select the Snippet generator.
3. Now, provide the username and password (GitHub) and click save.
4. The Credentials will have been added in the Registry Credentials section select the docker
below, then click on Generate pipeline script.
STEP 25: In Step 21, paste the above generator pipeline script in the Credentials ID and tool
name portion of the code.
STEP 26: Click > dashboard > python-webapp > build now.
RESULT:
Thus, the CI Pipeline has been successfully created.
AIM:
To create a CD pipeline in Jenkins and deploy it in the Cloud.
PROCEDURE:
STEP 1: Click Repositories > pythondemoapp > General. There, you will be able to see a
command under Docker commands. Copy that command.
STEP 2: Now, go to your GitHub account. Scroll down to Containers and copy the command
again for future use.
STEP 3: 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{
withDockerRegistry(credentialsId: 'dbc54abf-de2b-42b8-a0d2-f5539c9b8997',
toolName: 'docker') {
sh "docker images"
sh "docker run -d --rm -it -p 80:5000 jayashriashokkumar28112003/python-
webapp:latest"
}
}
}
}
STEP 5: 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.
AIM
To Create an Ansible Playbook for a simple web application infrastructure.
PROCEDURE
STEP 1: Create a directory named ansible-practice1 and then navigate into that
directory with the cd command.
STEP 2: Now create a playbook that contains the following content to be executed.
The content to be added in the playbook (playbook01.yml),
---
- hosts: localhost
tasks:
- name: Print message
debug:
msg: Hello Ansible World
RESULT:
Thus, creating and executing an ansible playbook for a simple web application
infrastructure has been executed successfully.
AIM
To build a simple application using Gradle.
PROCEDURE
4. Select the project type (application, library, etc.) by typing `2` and pressing Enter for
an application.
5. Choose the implementation language (Java, Kotlin, etc.) by typing `3` and pressing
Enter for Java.
6. Select the default build script language (Groovy or Kotlin) by typing `1` and pressing
Enter for Groovy.
7. Choose the testing framework (JUnit 4, TestNG, etc.) if prompted. The default is Junit4
8. Enter the project name when prompted (default is the directory name) & Enter the source
package when prompted (default is the directory name).
OUTPUT
RESULT
Thus, the Java application was successfully created using Gradle.
AIM
To install Ansible, configure Ansible roles and write playbooks.
PROCEDURE
Step 1: Refresh your system’s package index so that it is aware of the packages available.
Run the following command,
Step 2: The Ansible package and its dependencies are available in the default package
repositories to install the latest Ansible version, add its ppa repository.
Step 3: Now install the ansible latest version using the command,
$ sudo apt install ansible
Step 4: To check the list of directories and files present in the ansible, run the command as,
$ ls –la
Step 5: 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.
Step 7: 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,
$ cd prerequisites/tasks/
Then edit the main.yml file by the command,
$ sudo nano main.yml
Lastly, we are going to create a playbook 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
Step 8: Ensure that our roles are working as expected, and run the ansible playbook.
Run the following command,
$ sudo ansible-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.