0% found this document useful (0 votes)
2K views

Devops Lab Manual Final

Lab manual

Uploaded by

Bhuvanesh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

Devops Lab Manual Final

Lab manual

Uploaded by

Bhuvanesh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 75

lOMoARcPSD|34169792

Devops lab manual FInal

Devops (Anna University)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by Bhuvanesh ([email protected])
lOMoARcPSD|34169792

TAGORE ENGINEERING COLLEGE

RATHINAMANGALAM, CHENNAI-127.

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

CCS342 - DEVOPS

Name :

Reg. No :

Branch :

Year :

Semester :

Anna University∷Chennai
Regulation 2021

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

TAGORE ENGINEERING COLLEGE


RATHINAMANGALAM, CHENNAI-600127

LABORATORY RECORD

UNIVERSITY REGISTER NO.

Certified that this is the bonafide record of work done by

Mr. /Ms. of

Department in the laboratory

and submitted for the University Practical Examination conducted on

at TAGORE ENGINEERING COLLEGE, CHENNAI-127.

Record Mark:

Lab In-charge Principal Head of the Department

External Examiner Internal Examiner

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

VISION

To create an environment which is conducive to produce competent Computer Science Engineers


through quality education and research-oriented education and equip them for the needs of the industry and
society.

MISSION

The Department strives to contribute to the expansion of knowledge in the discipline of


Computer Science and Engineering by

 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.

PROGRAM SPECIFIC OBJECTIVES (PSOs)

1. Exhibit design and programming skills to build and automate business solutions using
cutting edge technologies

2. Strong theoretical foundation leading to excellence and excitement towards research, to


provide elegant solutions to complex problems.

3. Ability to work effectively with various engineering fields as a team to design, build and
develop system applications.

PROGRAM OUTCOMES POs

Engineering Graduates will be able to:

1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals


and an engineering specialization to the solution of complex engineering problems.

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.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

4. Conduct investigations of complex problems: Use research-based knowledge and research


methods including design of experiments, analysis and interpretation of data, and synthesis of the
information to provide valid conclusions.

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.

7. Environment and sustainability: Understand the impact of the professional engineering


solutions in societal and environmental contexts, and demonstrate the knowledge of, and need for
sustainable development.

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.

10. Communication: Communicate effectively on complex engineering activities with the


engineering community and with society at large, such as, being able to comprehend and write
effective reports and design documentation, make effective presentations, and give and receive
clear instructions.

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.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

TABLE OF CONTENTS

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

1. Create Maven Build Pipeline in Azure

Run Regression Tests Using


2.
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

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

Ex. No: 1 CREATE MAVEN BUILD PIPELINE IN AZURE

Date:

AIM
To build a maven build pipeline in Azure.

PROCEDURE

STEP 1: Create an account on the Azure DevOps website.

1. Go to https://azure.microsoft.com/en-in/products/devops/ website and sign in


using a GitHub account.

2. Create a new organization with a suitable name of your choice. Here


dhineshkumar1729 is the organization name.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

3. Create a new project named DevOps in private mode.

STEP 2: Installing IntelliJ IDEA

1. Download IntelliJ Idea from https://www.jetbrains.com/idea/download/?section=linux


and activate a free trialfor 30 days or through the following command.
$ sudo snap install intellij-idea-community --community
2. Open the IDE using the below command in the terminal.
$ intellij-idea-community
3. Java is a pre-requisite for using this IDE

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

STEP 3: Create a new Maven project using the IDE.

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.

STEP 4: Install GIT and configure it

1. Check whether git is installed using the following command.


$ git -version
2. Install git using
$ sudo apt install git

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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. Configure git using the below commands


$ git config --global user.name “Your_Name”
$ git config --global user.email “Your_Email_ID”

1. Go to https://github.com sign in with your account and create a new private repositorywith
the same name as your maven project.

1. Copy the SSH URL for the created repository.


2. Now go back to IDE’s terminal and execute the following commands
$ ssh-keygen -t rsa -b 4096 -C [email protected]
(press ENTER for all questions)
$ cat ~/.ssh/id_rsa.pub (copy the printed SSH key)
1. Now go to the SSH and GPG section in the GitHub settings option.
2. Click on the New SSH key button.
3. Choose a suitable name and paste the SSH key into the provided space.
4. Now get back to the IDE’s terminal and type the following command
$ git remote set-url origin [email protected]:dk172923/sample.git
(Here, [email protected]:dk172923/sample.git is the remote URL to use SSH
dk172923 – GitHub ID
sample.git – repository name)
1. Now finally run the push commands to push the code to the remote repository fromthe
local repository.
$ git push --set-upstream origin main (Type YES for prompted question)
$ git push

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

The code has been successfully pushed to the remote repository.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

STEP 5: Create a pipeline for the created maven repository.

1. Click on Pipelines on the left pane of the Azure DevOps website.

1. Click on the Create Pipeline button.


2. Choose the GitHub YAML option.

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


2. Give permissions if prompted to do so and sign in to your GitHub account if needed.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

3. Choose Maven Pipeline from the given options.


4. A YAML file is automatically created based on the configuration details found in the
pom.xml file in the repository.

1. Press the Save and Run button.


2. Create a commit message and press the run button again.
3. Click on the created Job from the Jobs table.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

A successful job completion would be like this.

RESULT
Thus, a maven build pipeline has been created using Azure.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

Ex. No: 2 RUN REGRESSION TESTS USING MAVEN BUILD


Date: PIPELINE IN AZURE

AIM

To run regression tests using the Maven build pipeline in Azure.

PROCEDURE

STEP 1: Create a new maven project in IntelliJ IDEA IDE.

1. Create a project with RegressionTesting as its name.


2. Choose the Maven build system and available JDK version.
3. Select the Create Git Repository option.

4. Wait for some time until the indexes of the project have been updated.
5. Add the following snippet of code into pom.xml

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

<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)

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

8. Right-click on the package and create a new class named MainTest

9. Paste the following into the MainTest.java file


package org.example;
import org.junit.Test;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import static org.junit.Assert.assertEquals;
public class MainTest {
@Test
public void testMainMethod() {
// Redirect standard output to capture console output
ByteArrayOutputStream outContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent));

// Call the main method


Main.main(new String[]{});

// Check if "Hello and welcome!" was printed


assertEquals("Hello and welcome!", outContent.toString().trim());

// Reset standard output


System.setOut(System.out);
}
}

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

STEP 2: Create a GitHub repository

1. Create a private repository with RegressionTesting as its name.

2. Execute the following commands in the terminal of IntelliJ IDEA

$ git init
$ git add .
$ git commit -m “regression”
$ git branch -M main
$ git remote add origin YOUR_REPOSITORY_LINK
$ git push -u origin main

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


your respective GitHub repository.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

3. The MainTest 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.

STEP 3: Create an Azure Pipeline

1. Open the Azure DevOps site

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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.

7. Configure the pipeline by choosing Maven

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

8. On the next page an azure-pipeline.yml file is generated automatically. Replace this


file with the following code

# 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.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

10. The following results can be obtained on the output page.

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.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

Ex. No: 3 INSTALL JENKINS IN CLOUD


Date:

AIM

To install Jenkins in the cloud (AWS).

PROCEDURE

STEP 1: Create an AWS account

1. Go to https://aws.amazon.com/ and create an AWS Account.

2. Provide a root email ID and username for the user.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

3. After Email verification set up your password.

4. Complete the sign-up process by providing additional information.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

7. Verify the phone number and perform a security check.

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

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

STEP 2: Create an EC2 instance.

1. Search EC2 in the search bar and choose EC2 from the services tab.

2. Click on the Launch Instance button.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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

4. Create a new key pair if you haven’t created one yet.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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.

6. In the Network Settings tab select the following options.


 Allow HTTPS traffic from the internet
 Allow HTTP traffic from the internet

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

9. Click on the Security tab and choose the Security Groups option.

10. Click on the Edit Inbound Rules button.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

13. A terminal is opened on a new tab in the same browser.

STEP 3: Installing Jenkins on the instance.

1. Execute the following commands on the terminal to update the OS.


$ clear
$ sudo apt update

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

2. Execute the following command to install Jenkins.

$ sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \


https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key

$ echo deb [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

$ sudo apt-get update

$ sudo apt-get install fontconfig openjdk-17-jre

$ sudo apt-get install Jenkins

These commands can also be found at https://pkg.jenkins.io/debian-stable/ for Debian


releases.

3. The following commands will start Jenkins.

$ sudo systemctl start Jenkins


$ sudo systemctl enable Jenkins
$ sudo systemctl status Jenkins

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

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

STEP 4: Configuring Jenkins

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.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

5. The installation will take some time to complete.

6. Create a user login on the next page. Provide the necessary information and press
Save and Continue.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

9. The Jenkins web page would look like below. Jobs can be built here.

RESULT:

Thus, Jenkins has been installed on the cloud.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

Ex. No: 4 CREATE CI PIPELINE USING JENKINS

Date:

AIM:
To create a CI pipeline using Jenkins.

PROCEDURE:

STEP 1: 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.)

STEP 2: Now you have moved into your own GitHub account.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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"
}
}
}
}

Now, Click on Save.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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

2. To Add the Jenkins User to the Docker Group:


$sudo usermod -aG docker jenkins
(Replace ‘jenkins’ with the actual username of the Jenkins user)

3. To Verify the Group Membership:


$groups Jenkins

4.To install the docker:


$sudo apt install docker.io

5.To restart jenkins:


$sudo systemctl restart Jenkins

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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"
}
}
}
}
}
}

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

STEP 22: Click on pipeline syntax and Select the Snippet generator

1. In the Sample step, choose the git: Git.

2. Paste your GitHub URL in the URL section.


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

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

4. Click on Generate pipeline script.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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.

1. In the Sample step, choose the below option.

2. Make the Registry Credentials null and click Jenkins.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

STEP 25: In Step 21, paste the above generator pipeline script in the Credentials ID and tool
name portion of the code.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

STEP 26: Click > dashboard > python-webapp > build now.

STEP 27: Now CI Pipeline has been built Successfully.

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

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

Ex. No: 5 CREATE A CD PIPELINE IN JENKINS AND DEPLOY IN CLOUD


Date:

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.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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"
}
}
}
}

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

STEP 4: Click on Dashboard > python-webapp > Build Now

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.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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 infrastructure.

PROCEDURE

STEP 1: Create a directory named ansible-practice1 and then navigate into that
directory with the cd command.

The following commands are used to create a directory,


$ cd ~
$ mkdir ansible-practice1
$ cd ansible-practice1

To add content to playbook use the following commands,


$ nano playbook01.yml

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

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

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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 -i inventory playbook-01.yml -u sammy

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

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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.
Step 4: Select project type (application).
Step 5: Choose implementation language (Java).
Step 6: Select build script language (Groovy).
Step 7: Choose testing framework (JUnit 4).
Step 8: Enter project name.
Step 9: Enter source package.

1. Install gradle using the following command

2. Create a directory named java_application and change directory:

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

3. Run the gradle init command to create a new Gradle project

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.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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).

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

OUTPUT

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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

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

$ sudo apt update

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.

$ sudo apt upgrade


$ sudo apt install -y software-properties-common
$ sudo add-apt-repository --yes --update ppa:ansible/ansible

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

Step 3: 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

Step 4: To check the list of directories and files present in the ansible, run the command as,
$ ls –la

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

Then check the host file by,


$ sudo nano hosts

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.

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

Step 6: Create three ansible roles as follows:


The prerequisites role – Installs git.
The postgresql role – Installs postgresql service.
The apache role – Installs the Apache webserver.
Use the following commands to create the above,

$ sudo ansible-galaxy init prerequisites


$ sudo ansible-galaxy init PostgreSQL
$ sudo ansible-galaxy init apache
$ ls

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

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

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

Next for PostgreSQL,


$ cd PostgreSQL/tasks/
$ sudo nano main.yml
Then add the content to this main.yml file as,
# tasks file for PostgreSQL
- name: Install PostgreSQL
apt:
name: postgresql
state: present
update_cache: yes
- name: Start PostgreSQL service
systemd:
name: postgresql
state: started
enabled: yes

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

Finally for the apache web server,


$ cd apache/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 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

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

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

Downloaded by Bhuvanesh ([email protected])


lOMoARcPSD|34169792

RESULT
Thus, installing ansible, configuring ansible roles and writing playbooks have been
executed successfully.

Downloaded by Bhuvanesh ([email protected])

You might also like