Ex.
No: 1
CREATE MAVEN BUILD PIPELINE IN AZSURE
Date:
Aim:
To set up a Maven pipeline in Microsoft Azure Portal to automate the build and
deployment process of Java applications.
Prerequisites:
An active Microsoft Azure account
Basic understanding of Maven
Java application source code hosted in a version control system (e.g., GitHub)
Steps:
1. Sign in to Azure Portal:
Open your web browser and navigate to the [Azure Portal] ([Link]
Sign in using your Azure account credentials.
2. Create a New Azure DevOps Project: -
Click on Create a resource.
Search for Azure DevOps and select it.
Click Create and follow the prompts to create a new Azure DevOps organization if
you haven't already done so.
Once the organization is created, create a new project within it.
3. Set Up a New Pipeline:
In your Azure DevOps project, navigate to Pipelines> Create Pipeline.
Choose your source control repository where your Java application is hosted (e.g., GitHub).
Select the repository and configure the branch that contains your Maven project. - Choose
Maven as the pipeline template.
4. Configure Pipeline:
Azure Pipelines automatically generates a `[Link]` file based on the
Maven template. You may need to customize this file based on your project
requirements.
Specify the Maven goals and options in the `[Link]` file.
For example: [Link]
trigger:
branches:
include:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Maven@3
inputs:
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
mavenPomFile: '[Link]'
goals: 'clean package'
publishJUnitResults: false
testResultsFiles: '**/surefire-reports/TEST-
*.xml' javaHomeOption: 'JDKVersion'
jdkVersionOption:
'1.1
mavenVersionOption: 'Default' jdkArchitectureOption:
'x64' mavenAuthenticateFeed: false
5. Save and Run Pipeline:
Save the changes made to the `[Link]` file.
Click on Run to trigger the pipeline. Azure Pipelines will automatically start the
build process based on the configuration provided.
6. Monitor Pipeline Execution:
Monitor the progress of the pipeline execution in Azure Pipelines. You can view
detailed logs to track the build process.
If any errors occur during the build process, troubleshoot them based on the
error messages provided.
7. Deployment (Optional):
After a successful build, you can add deployment tasks to your pipeline to deploy the
built artifacts to Azure services like Azure App Service or Azure Kubernetes Service
(AKS).
Configure deployment tasks according to your deployment targets and requirements.
8. Post-Deployment Testing (Optional):
Optionally, you can add post-deployment testing tasks to your pipeline to ensure the
deployed application functions correctly.
Configure testing tasks such as integration tests or smoke tests as per your
project's testing strategy.
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
OUTPUT:
Step 1: Organization is created
Step 2: Organization by clicking the new project button
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
Step 3: Create Pipeline
Step 4: Configure new project.
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
Viva Questions:
1. What is Azure DevOps?
Azure DevOps is a cloud-based set of tools by Microsoft for DevOps lifecycle management.
It supports CI/CD, version control (with Git), build and release pipelines, testing, and more.
2. What is Maven?
Maven is a build automation and project management tool for Java-based projects. It uses
a [Link] file to manage project dependencies, build configuration, and plugins.
3. What is a CI/CD pipeline?
A CI/CD pipeline is an automated workflow that allows developers to continuously integrate
and continuously deliver software. CI involves building and testing code changes
automatically; CD handles deploying these changes to environments.
4. What is the purpose of a build pipeline?
A build pipeline automates the steps required to compile, build, test, and package your code.
It ensures code quality and speeds up the development process.
5. What is the role of the [Link] file in Maven?
The [Link] file (Project Object Model) defines project structure, dependencies, plugins, and
build configurations in a Maven project.
AIM & PROGRAM OUTPUT VIVA TOTAL DISSEMMINATION TIMELY GRAND
ALGO EXECUTION & VOCE (A1) TO SUBMISSION TOTAL
RITH & RESULT (5M) (30M) LEARNED PO’S OF RECORD (A1+B1)
M DEBUGGING (10M) &PSO’S (B1) (40M)
(5M) (10M) (10M)
Result:
Thus, the above procedure will Create a Maven Build Pipeline in Azure.
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
[Link] RUN REGRESSION TESTS USING MAVEN
BUILD PIPELINE IN AZURE
Date:
Objective:
The objective of this lab is to set up a Maven build pipeline in Azure DevOps to execute
regression tests for a Java application.
Prerequisites:
An active Microsoft Azure account
Basic understanding of Maven
Java application source code with regression
tests
Azure DevOps project created
Steps:
1. Sign in to Azure Portal:
Open your web browser and navigate to the [Azure Portal] ([Link]
Sign in using your Azure account credentials.
2. Access Azure DevOps:
Navigate to your Azure DevOps project.
3. Set Up a New Pipeline:
Navigate to Pipelines > Create Pipeline.
Choose your source control repository where your Java application is hosted (e.g., GitHub).
Select the repository and configure the branch that contains your Maven project.
Choose Maven as the pipeline template.
4. Configure Pipeline:
Azure Pipelines automatically generates a `azure
[Link]` file based on the Maven template. Customize this file to include
regression test execution.
Add a new step in the `[Link]` file to run regression tests. For example: [Link]
trigger:
branches
:
include
:-
main
pool:
vmImage: 'ubuntu-
latest' steps:
- task:
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
Maven@3
inputs:
mavenPomFile:
'[Link]' goals:
'clean install'
publishJUnitResults
:
true
testResultsFiles: '**/surefire-
reports/TEST-*.xml'
javaHomeOption:
'JDKVersion' jdkVersionOption: '1.11'
mavenVersionOption:
'Default'
jdkArchitectureOption:
'x64'
mavenAuthenticateFeed:
false
- script: 'mvn test -
Dtest=RegressionTestSuite'
displayName: 'Run Regression
Tests'
5. Save and Run Pipeline:
Save the changes made to the `[Link]` file.
Click on Run to trigger the pipeline. Azure Pipelines will start the build process and
execute the regression tests.
6. Monitor Pipeline Execution:
Monitor the progress of the pipeline execution in Azure Pipelines. You can view
detailed logs to track the build process and test execution.
If any errors occur during the build or test execution, troubleshoot them based on the
error messages provided.
7. Review Test Results:
Once the pipeline execution is complete, review the test results generated by the regression tests.
Check for any failed tests and investigate the reasons for their failure.
8. Incorporate Test Reporting:
Optionally, you can integrate test reporting tools like Allure or Extent Reports
to generate comprehensive test reports.
Configure the pipeline to publish the test reports as artifacts or attach them to the build
summary for better visibility.
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
OUTPUT:
Step1: new resource, select go to resource.
Step 2: Azure Load Testing resource, select Tests
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
Step 3: On the Basics tab, enter the Test name and Test description information.
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
Viva Questions:
1. What is regression testing?
Regression testing is a type of software testing that ensures new changes or updates in the code
do not break the existing functionality. It is typically performed after code changes like bug fixes,
enhancements, or new feature additions.
2. What is the purpose of running regression tests in a Maven pipeline?
Running regression tests in a Maven pipeline ensures that the application remains stable after
every build. It automates test execution and provides quick feedback on whether the recent changes
have impacted existing features.
3. How do you configure a Maven pipeline in Azure DevOps?
Creating a new pipeline (using YAML or classic editor)
Specifying the Maven task
Defining goals like clean test or verify
Ensuring the Maven tool is installed or selected as part of the pipeline agent
Optionally publishing test results
4. How can you view the test results in Azure DevOps?
Add a Publish Test Results task to the pipeline and point it to the test result file (e.g.,
target/surefire-reports/*.xml). Azure DevOps then displays the test report in the pipeline summary
under the "Tests" tab
AIM & PROGRAM OUTPUT VIVA TOTAL DISSEMMINATION TIMELY GRAND
ALGORI EXECUTION & VOCE (A1) TO SUBMISSION TOTAL
THM & RESULT (5M) (30M) LEARNED PO’S OF RECORD (A1+B1)
(5M) DEBUGGING (10M) &PSO’S (B1) (40M)
(10M) (10M)
Result:
Thus, the above programs completed run regression tests using a Maven build pipeline
in Azure
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
[Link]: 3
INSTALLING JENKINS ON AZURE CLOUD
Date:
Aim:
The objective of this lab is to guide you through the process of installing Jenkins on the
Azure cloud platform.
Prerequisites:
An active Microsoft Azure account - Basic familiarity with Azure Portal
Understanding of virtual machines and networking concepts
Lab Steps:
1. Sign in to Azure Portal:
Open your web browser and navigate to the [Azure Portal] ([Link]
Sign in using your Azure account credentials.
2. Create a Virtual Machine:
Click on Create a resource.
Search for Virtual machine and select it.
Click Create and fill in the required details:
Subscription: Select your subscription.
Resource group: Create a new one or use an existing one.
Virtual machine name: Provide a name for your Jenkins VM. - Region: Choose the
region closest to your location.
Image: Select an Ubuntu Server or any other preferred Linux distribution. - Size: Choose
an appropriate VM size based on your requirements.
Authentication type: Select SSH public key or password for authentication.
Username and Password/SSH public key: Provide the credentials for accessing the VM.
Inbound port rules: Allow ports 22 (SSH) and 8080 (for Jenkins). - Click Review +
create and then Create to provision the VM.
3. Access the Virtual Machine:
Once the VM is created, navigate to it from the Azure Portal.
Click on Connect to get the connection details (SSH command or RDP file) to access the VM.
4. Connect to the Virtual Machine:
Use SSH (for Linux VM) or Remote Desktop (for Windows VM) to connect to the virtual
machine.
Open a terminal or command prompt and connect to the VM using the provided credentials
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
5. Install Java Development Kit (JDK):
Jenkins requires Java to run. Install Java on the virtual machine using the package
manager for your chosen operating system.
6. Install Jenkins:
Add the Jenkins repository key to the system:
Update the package index:
sudo apt update -
Install Jenkins:
sudo apt install jenkins -y
7. Start and Enable Jenkins Service: -
Start the Jenkins service:
sudo systemctl start jenkins -
Enable Jenkins to start on boot:
sudo systemctl enable jenkins
8. Access Jenkins Web Interface:
Open a web browser and navigate to `[Link]
Follow the instructions to complete the Jenkins setup wizard, including unlocking
Jenkins and installing recommended plugins.
Create an admin user and take note of the credentials.
9. Configure Jenkins:
Once Jenkins is set up, you can configure additional settings such as security,
plugins, and system settings based on your requirement
10. Integration with Azure Services (Optional):
You can integrate Jenkins with other Azure services such as Azure DevOps,
Azure Container Registry, or Azure Kubernetes Service (AKS) to automate
CI/CD pipelines.
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
OUTPUT:
Step 1: Enter the IP Address in url:[Link]
Step 2: Sign in to the AWS Management Console.
Step 3: Open the Amazon EC2 console
Step 4: select Security Groups
Step 5: choose Instances
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
Viva Questions:
1. What is Jenkins?
Jenkins is an open-source automation server used for continuous integration and continuous
delivery (CI/CD). It helps automate parts of the software development process like building, testing,
and deploying code.
2. Why do we use Jenkins?
We use Jenkins to automate repetitive tasks in software development, such as compiling
code, running tests, and deploying applications. This speeds up development and
ensures consistent results
.
3. What are the basic requirements to install Jenkins in a cloud environment?
A virtual machine (e.g., EC2 on AWS, Compute Engine on GCP)
Java installed (Jenkins requires Java 11+)
Open ports (usually 8080 for Jenkins web UI)
Adequate system resources (minimum 1GB RAM, 50GB disk space recommended)
4. How can Jenkins scale in the cloud?
Use a master-agent architecture
Spin up agents dynamically using:
EC2 (with EC2 Plugin)
Kubernetes (Jenkins Kubernetes Plugin)
Docker agents
Use load balancers if deploying Jenkins in HA (High Availability) mode
5. What are some common plugins used in cloud-based Jenkins setups?
Pipeline plugin
Blue Ocean
Git/GitHub integration
Cloud provider plugins (e.g., AWS EC2, Azure VM Agents, GCP Agents)
Kubernetes plugin
AIM & PROGRA OUTPUT VIVA TOTAL DISSEMMINATION TIMELY GRAND
ALGOR M & VOCE (A1) TO SUBMISSION TOTAL
ITHM EXECUTI RESULT (5M) (30M) LEARNED PO’S OF RECORD (A1+B1)
(5M) ON (10M) &PSO’S (B1) (40M)
& (10M)
DEBUGG
ING
(10M)
Result:
Thus, the above install Jenkins in a cloud environment and completed successfully completed.
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
[Link]: 4
CREATING A CI PIPELINE USING JENKINS
Date:
Aim:
The objective of this lab is to guide the process of setting up a Continuous Integration (CI)
pipeline using Jenkins to automate the build and testing process of a sample application.
Prerequisites:
Jenkins installed and accessible (Refer to the "Installing Jenkins on Azure
Cloud" lab manual)
Sample application source code hosted in a version control system (e.g., GitHub)
Basic understanding of Jenkins and version control systems
Steps:
1. Access Jenkins Dashboard:
Open a web browser and navigate to your Jenkins instance (e.g.,
[Link]
Log in with your Jenkins admin credentials.
2. Install Required Plugins:
Navigate to Manage Jenkins > Manage Plugins > Available.
Search for and install the following plugins if not already installed:
Git Plugin
Pipeline Plugin
3. Create a New Jenkins Pipeline:
Navigate to New Item from the Jenkins dashboard.
Enter a name for your pipeline (e.g., "SampleApp_CI_Pipeline").
Choose **Pipeline** as the project type and click **OK**.
4. Configure Pipeline:
In the pipeline configuration page:
Under General, define your pipeline description.
Under Pipeline, select **Pipeline script from SCM** as the Definition.
Choose your version control system (e.g., Git) and provide the repository URL.
Specify the branch to build (e.g., `main` or `master`).
Save your configuration.
5. Create Jenkinsfile:
In your source code repository, create a `Jenkinsfile` at the root level.
Define your pipeline stages and steps in the `Jenkinsfile`.
For example:
pipeline {
agent
any
stages {
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
stage('Checkout')
{ steps {
git branch: 'main', url:
'[Link] username/[Link]'
}
}
stage('Build')
{ steps {
sh 'mvn clean package'
}
}
stage('Test')
{
steps {
sh 'mvn test'
}
}
// Add more stages as needed (e.g., Deploy, Publish
Artifacts) }
post {
always
{
// Clean up or
notify}
success {
// Notify success
}
failure {
// Notify
failure }
}
}
6. Save and Run Pipeline:
Once `Jenkins file` is configured, save it in repository.
Go back to Jenkins dashboard and navigate to your pipeline.
Click on Build Now to trigger the pipeline execution.
7. Monitor Pipeline Execution:
Monitor the progress of your pipeline on the Jenkins dashboard.
Click on the build number to view detailed logs of each
Troubleshoot any issues encountered during the build and testing process.
8. Review Test Results:
If your pipeline includes testing stages, review the test results to ensure
the application meets quality standards.
Check for any failed tests and investigate the reasons for their failure.
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
9. Post-Build Actions (Optional):
Configure post-build actions such as sending notifications, archiving artifacts,
or triggering downstream jobs based on build results.
10. Integration with Version Control System:
Jenkins can automatically trigger pipeline builds on code changes pushed to the
repository. Ensure your pipeline is configured to listen for changes and trigger
builds accordingly.
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
OUTPUT:
Step 1: Login into your Jenkins account as shown below.
Step 2: Once logged in, the user will be redirected to the Jenkins console,
Step 3: To create a new project, select the option.
Step 4: Now a list of options will be visible on the screen.
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
Step 5: Once redirected.
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
Viva Questions:
1. What is a CI pipeline in Jenkins?
A CI (Continuous Integration) pipeline in Jenkins is an automated process that builds, tests, and
integrates code changes from developers into a shared repository, helping identify issues early and
ensure software quality.
2. What is a Jenkins file?
A Jenkins file is a text file that defines the CI/CD pipeline using Groovy syntax. It can be stored in
the source code repository for versioning and reproducibility.
3. What plugins are useful for CI pipelines in Jenkins?
Pipeline Plugin
Git Plugin
Maven Integration Plugin
JUnit Plugin
Credentials Binding Plugin
Docker Plugin (if using containers)
4. What are common CI issues and how to handle them?
Build failures → Check dependencies, logs
Test flakiness → Isolate flaky tests
Merge conflicts → Use branching strategies
Pipeline stuck → Restart Jenkins agent or clean workspace
5. How do you trigger a Jenkins pipeline automatically?
Poll SCM (e.g., check Git repo every X minute)
Webhook (e.g., GitHub pushes notify Jenkins)
Build periodically (cron-like syntax)
Trigger from another job or external tool
AIM & PROGRAM OUTPUT VIVA TOTAL DISSEMMINATION TIMELY GRAND
ALGO EXECUTION & VOCE (A1) TO SUBMISSION TOTAL
RITH & RESULT (5M) (30M) LEARNED PO’S OF RECORD (A1+B1)
M DEBUGGING (10M) &PSO’S (B1) (40M)
(5M) (10M) (10M)
Result:
Thus, the above program was successfully completed CD pipeline in Jenkins and deployment in Cloud.
.
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
[Link]: 5
CREATING A CD PIPELINE IN JENKINS AND
DEPLOYING TO AZURE CLOUD
Date:
Aim:
The objective of this lab is to guide you through the process of setting up a Continuous Delivery
(CD) pipeline using Jenkins to automate the deployment of a sample application to the Azure cloud
platform.
Prerequisits:
Sample application source code hosted in a version control system (e.g.,
GitHub) Azure account with necessary permissions to create and
manage resources
Basic understanding of Jenkins, version control systems, and Azure
services
Steps:
1. Access Jenkins Dashboard:
Open a web browser and navigate to your Jenkins instance (e.g., [Link]
ip>:8080).
Log in with your Jenkins admin credentials.
2. Install Required Plugins:
Navigate to Manage Jenkins >Manage Plugins >Available.
Search for and install the following plugins if not already installed:
Azure Credentials Plugin.
Azure App Service Plugin.
Pipeline Plugin.
Git Plugin.
3. Configure Azure Credentials:
Navigate to Manage Jenkins >Manage Credentials>(Global)
Click Add Credentials and select Microsoft Azure Service Principal
Enter your Azure Service Principal details (Client ID, Client Secret, Subscription ID,
and Tenant ID) and give it an appropriate ID (e.g., azure-credentials).
Click OK to save the credentials.
4. Create a New Jenkins Pipeline:
Navigate to New Item from the Jenkins dashboard.
Enter a name for your pipeline (e.g., "SampleApp_CD_Pipeline").
Choose Pipeline as the project type and click OK .
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
5. Configure Pipeline:
In the pipeline configuration page:
Under General, define your pipeline description.
Under Pipeline, select Pipeline script from SCM as the
Definition.
Choose your version control system (e.g., Git) and provide the repository URL.
Specify the branch to build (e.g., main or master).
Save your configuration.
6. Create Jenkins file:
In your source code repository, create a Jenkins file at the root level.
Define your pipeline stages and steps in the Jenkins file.
Include stages for build, test, and deploy. For example:
pipeline
agent
any
stages {
stage('Checkout')
steps {
git branch:'main',url:
'[Link] username/sample-
[Link]'
stage('Build') {
steps {
sh 'mvn clean package'
}
stage('Test')
{ steps {
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
sh 'mvn test'
stage('Deploy to Azure App Service') {
steps {
azureWebAppPublish appName: 'your-app-name',
resourceGroup: 'your-resource-group',
filePath: 'target/*.war'
}}}
post {
always {
// Clean up or notify
success {
// Notify success
failure {
// Notify failure
}}
7. Save and Run Pipeline:
Once your Jenkins file is configured, save it in your repository.
Go back to your Jenkins dashboard and navigate to your pipeline.
Click on Build Now to trigger the pipeline execution.
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
8. Monitor Pipeline Execution:
Monitor the progress of your pipeline on the Jenkins dashboard.
Click on the build number to view detailed logs of each stage.
Troubleshoot any issues encountered during the build, test, or deployment process.
9. Verify Deployment:
Once the pipeline execution is complete, verify that your application is deployed to
the Azure App Service.
Access your deployed application using the Azure App Service URL.
10. Post-Deployment Actions (Optional):
Optionally, configure post-deployment actions such as setting up custom domain,
configuring SSL, or integrating with Azure monitoring services.
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
OUTPUT:
Step 1: Click on Freestyle project
Step 2: Source Code Management window.
Step 3: Jenkins needs to fetch all the repository files
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
Step 4: Go to the Build tab and add the build step
Step5: Drop- down file menu
Step 6: Build Now
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
Viva Questions:
1. What is Continuous Deployment (CD)?
Continuous Deployment is the practice of automatically deploying every code change that
passes the CI pipeline to a production or staging environment, with no manual intervention.
2. How is CD different from CI?
CI (Continuous Integration) focuses on building and testing code automatically. CD
(Continuous Deployment) takes it further by automatically deploying the code to production
or cloud environments.
3. What tools and plugins are used for deploying to Azure from Jenkins?
Azure CLI
Azure Service Principal (for authentication)
Azure Credentials Plugin
Azure App Service Plugin (for App Service deployments)
Azure DevOps Plugin (optional for integration)
Publish Over SSH (if using VMs)
4. How do you manage secrets for Azure deployment in Jenkins?
Use Jenkins Credentials Manager
Store:
Azure SP credentials
SSH keys
Environment secrets (API keys, DB creds)
Access using with Credentials block
AIM & PROGRAM OUTPUT VIVA TOTAL DISSEMMINATION TIMELY GRAND
ALGO EXECUTION & VOCE (A1) TO SUBMISSION TOTAL
RITH & RESULT (5M) (30M) LEARNED PO’S OF RECORD (A1+B1)
M DEBUGGING (10M) &PSO’S (B1) (40M)
(5M) (10M) (10M)
Result:
Thus, the above program was successfully completed CD pipeline in Jenkins and deploy in Cloud
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
CREATING AN ANSIBLE PLAYBOOK FOR A SINGLE
[Link]: 6
WEB APPLICATION INFRASTRUCTURE
Date:
Aim:
The objective of this lab is to guide the process of creating an Ansible playbook to provision
and configure a single web application infrastructure. The playbook will automate the setup of
web server, database server, and any other required components for hosting the web
application.
Prerequisites:
Ansible installed on your local machine or a control node
Basic understanding of Ansible concepts such as playbooks, roles, and tasks
Access to target servers (virtual machines or cloud instances) where the infrastructure
will be provisioned
Steps:
1. Setup Ansible:
Ensure Ansible is installed on your local machine or a control
node.
If Ansible is not installed, you can follow the official Ansible
documentation for installation instructions.
2. Define Inventory:
Create an inventory file ([Link]) listing the target servers where
you want to provision the infrastructure.
Example [Link] :
csharpCopy code
[web_servers]
web1 ansible_host=[Link]
web2 ansible_host=[Link]
[db_servers]
db1 ansible_host=[Link]
3. Create Ansible Playbook:
Create a playbook file (webapp_infrastructure.yml) to define the tasks
for provisioning the infrastructure.
Define tasks for installing required packages, configuring web server, setting up
database server, etc.
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
Example
webapp_infrastructure.yml :
yamlCopy code
- name: Provision Web Application
Infrastructure hosts: web_servers
become:
true tasks:
- name: Install Apache web server
yum:
name: httpd
state: present
tags:
- apache
- name: Start Apache
service service:
name:
httpd state:
started
tags:
- apache
- name: Provision Database
Server hosts: db_servers
become:
true tasks:
- name: Install MySQL
server yum:
name: mysql-server
state: present
tags:
- mysql
- name: Start MySQL
service service:
name:
mysqld
state: started
tags:
- mysq l
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
4. Run Ansible Playbook:
Open a terminal or command prompt.
Navigate to the directory where your playbook and inventory files are
located. Run the Ansible playbook using the following command:
cssCopy code
ansible-playbook -i inventory
.ini
webapp_infrastructure .yml
5. Verify Infrastructure:
Once the playbook execution is complete, verify that the infrastructure has been
provisioned as expected.
Access the web servers' IP addresses in a web browser to verify that Apache is serving
web pages.
Connect to the database server to verify that MySQL service is running.
6. Customize and Expand:
Customize the playbook according to your specific requirements.
Expand the playbook to include additional tasks such as deploying the web
application code, configuring load balancers, setting up monitoring, etc.
OUTPUT:
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
Viva Questions:
1. What is Ansible and why is it used?
Ansible is an open-source configuration management and automation tool. It’s used to automate
infrastructure provisioning, application deployment, and configuration management using YAML-based
playbooks.
2. What is a playbook in Ansible?
A playbook is a YAML file that contains a list of tasks to be executed on remote servers. It defines
the desired state of a system using a set of instructions.
3. What are Ansible roles and why are they important?
Roles help structure playbooks into reusable, modular components (e.g., separate roles for web,
db, app). This improves scalability and maintainability.
4. What components are typically included in a single web application infrastructure?
Web Server (e.g., Nginx, Apache)
Application Code ([Link], PHP, Python, etc.)
Database (e.g., MySQL, PostgreSQL)
Firewall/Ports Configuration
Service Management (start/enable app services)
AIM & PROGRAM OUTPUT VIVA TOTAL DISSEMMINATION TIMELY GRAND
ALGO EXECUTION & VOCE (A1) TO SUBMISSION TOTAL
RITH & RESULT (5M) (30M) LEARNED PO’S OF RECORD (A1+B1)
M DEBUGGING (10M) &PSO’S (B1) (40M)
(5M) (10M) (10M)
Result:
Thus, the Creation of Ansible Playbook for a Single Web Application Infrastructure was
successfullycompleted.
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
[Link]: 7
BUILD A SIMPLE APPLICATION USING GRADLE.
Date:
Aim:
To create a simple Java application using Gradle to build and manage dependencies.
Algorithm:
1. Create a New Java Project:
Create a new directory for your project and navigate Into It.
mkdir SimpleJavaApp
cd SimpleJavaApp
2. Create Project Structure:
Create the basic project structure With a source directory.
mkdir -p src/main/java
3. Create Java Class:
Create a sample Java class. Save it as java ‘[Link]’ in ‘src/main/java’
public class SimpleApp{
public static void main (String[] args){
[Link](“Hello, Gradle!”);
}
4. Create Gradle Build Script:
Create a file named ‘[Link]’ in the project root
plugins {
id ‘java’
}
repositories {
mavenCentral ( )
}
dependencies {
// Define your dependencies here
application {
mainClassName='SimpleApp '
}
You can customize the ‘dependencies’ block based on the libraries or frameworks you want to use
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
5. Build the Project:
Open a terminal in the project directory
gradle build
Gradle will download dependencies, compile the code, and build the project You should see a
'build’ directory created with the compiled classes and JAR file.
6. Run the Application:
Run the application using the following command:
java -jar build/libs/[Link]
You should see the 'Hello, Gradle!' message printed to the console
OUTPUT:
The output in the terminal as Gradle downloads dependencies, compiles the code, and
builds the JAR file.
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
Viva Questions:
1. What is Gradle?
Gradle is a powerful build automation tool used primarily for Java-based applications. It uses a
domain-specific language based on Groovy or Kotlin and supports dependency management, compilation,
testing, packaging, and deployment.
2. How is Gradle different from Maven and Ant?
a. Ant: No built-in dependency management
b. Maven: Uses XML configuration ([Link])
c. Gradle:
i. Uses Groovy/Kotlin DSL
ii. More flexible and faster with incremental builds and a rich plugin system
[Link] is the Gradle Wrapper? Why is it useful?
The Gradle Wrapper (gradlew, [Link]) allows anyone to build the project without installing
Gradle manually. It ensures consistent Gradle versions across environments.
[Link] are the key files in a basic Gradle project?
1. [Link]: Main build script
2. [Link]: Defines the root project and subprojects
3. [Link]: Used to run Gradle with a specific version
4. src/main/java: Source code directory
5. src/test/java: Test code directory
AIM & PROGRAM OUTPUT VIVA TOTAL DISSEMMINATION TIMELY GRAND
ALGO EXECUTION & VOCE (A1) TO SUBMISSION TOTAL
RITH & RESULT (5M) (30M) LEARNED PO’S OF RECORD (A1+B1)
M DEBUGGING (10M) &PSO’S (B1) (40M)
(5M) (10M) (10M)
Result:
Thus, the simple application using Gradle was successfully completed.
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
[Link]: 8 INSTALL ANSIBLE AND CONFIGURE ANSIBLE ROLES AND TO
WRITE PLAYBOOKS
Date:
Aim:
To install Ansible, configure Ansible roles, and write playbooks for managing
configurations on target machines.
Algorithm:
1. Install Ansible:
• On your control machine (the machine from which you Will run Ansible). install
Ansible. The installation steps vary based on your operating system
For example, on Ubuntu:
sudo apt update
sudo apt install ansible
On CentOS:
sudo yum install ansible
Configure Ansible Roles:
1. Create Ansible Roles Directory:
• Create a directory structure for your Ansible roles.
mkdir -p -/ansible-roles
2. Create Roles:
• Inside the ‘-/ansibie roles’ directory, create subdirectories for each role
cd -'ansible-roles
mkdir common apache mysql
3. Organize Role Structure:
• Inside each role directory. create directories for tasks, handlers,defaults, and files.
cd common
mkdir tasks handlers defaults files
4. Write Tasks and Handlers:
• Write tasks in the ‘tasks/main .yml’ file for each role and corresponding
handlers in the ‘handlers/main. yml’ file.
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
name: Update package cache
apt :
update _ cache: yes
become: true
Example (common/handlers/[Link]):
name: Restart services
service :
name:”(( item ) ) "
state:restarted
loop:
-apache2
-mysql
Write playbooks:
1. Create Ansible Playbooks Directory:
• Create a directory for your Ansible playbooks.
mkdir- /ansible-playbooks
2. Write Playbooks:
• Inside the ‘-/ansible-playbooks’ directory, create YAML files for your
playbooks. Example (-/ansible-playbooks/[Link])
hosts: web servers
become: true
roles:
-common
-apache
Example (-/ansible-playbooks/[Link]).
hosts: db_servers
become: true
roles:
-common
-mysql
3. Run Playbooks:
• Run the playbooks using the ‘ansible-playbook’ command.
ansible-playbook-i inventory. ini-/ansible-playbooks/[Link]
ansible-playbook-i inventory. ini-/ansible-playbooks/[Link]
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
OUTPUT:
The output in the terminal as Ansible executes tasks defined in the playbooks and roles.
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY
Viva Questions:
1. What is an Ansible role?
An Ansible role is a modular structure for organizing playbooks. It allows separation of variables,
tasks, handlers, and templates in a reusable format.
2. What is the difference between vars and defaults in a role?
defaults has the lowest priority in the variable hierarchy.
vars has higher priority, overriding values from defaults.
3. What is a playbook in Ansible?
A playbook is a YAML file that defines a set of tasks to be run on managed hosts. It contains
plays, each mapping a group of hosts to tasks.
4. What module is used to install packages in Ansible?
On Debian/Ubuntu: apt
On RedHat/CentOS: yum or dnf
AIM & PROGRAM OUTPUT VIVA TOTAL DISSEMMINATION TIMELY GRAND
ALGO EXECUTION & VOCE (A1) TO SUBMISSION TOTAL
RITH & RESULT (5M) (30M) LEARNED PO’S OF RECORD (A1+B1)
M DEBUGGING (10M) &PSO’S (B1) (40M)
(5M) (10M) (10M)
Result:
Upon successful execution of the playbooks, target machines will be configured based on the
roles and tasks defined. Ansible will manage configurations, ensuring consistency across
infrastructure.
PSVPEC/CSE/IT/22CS22E DEVOPS LABAROTORY