0% found this document useful (0 votes)
8 views77 pages

Y21acs570 Devops Final

The document outlines a series of exercises demonstrating Git commands, including cloning, committing, and pushing changes to remote repositories. It details the process of creating local repositories, configuring user information, and managing branches. Additionally, it covers fetching and merging updates from remote repositories, showcasing practical applications of Git in a DevOps lab setting.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views77 pages

Y21acs570 Devops Final

The document outlines a series of exercises demonstrating Git commands, including cloning, committing, and pushing changes to remote repositories. It details the process of creating local repositories, configuring user information, and managing branches. Additionally, it covers fetching and merging updates from remote repositories, showcasing practical applications of Git in a DevOps lab setting.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 77

4/4 B.

Tech CSE Y21ACS570 DevOps Lab

Exercise-1:
Demonstration of Git commands: cloning, updating, and pushing changes to a
remote repository.

[ec2-user@Y21ACS570-Gittomcatmaven ~]$ sudo su


[root@Y21ACS570-Gittomcatmaven ec2-user]# sudo yum
update
Last metadata expiration check: 0:10:51 ago on Sun Dec 15 04:56:07
2024. Dependencies resolved.
Nothing to do.
Complete!
[root@Y21ACS570-Gittomcatmaven ec2-user]# sudo yum install git -y
Last metadata expiration check: 0:10:58 ago on Sun Dec 15 04:56:07
2024. Dependencies resolved.
=======================================================================
===
==================================================================
Package Architecture
Version Repository Size
=======================================================================
===
==================================================================
Installing:
.
.
perl-TermReadKey-2.38-9.amzn2023.0.2.x86_64 perl-lib-
0.65- 477.amzn2023.0.6.x86_64
Complete!
[root@Y21ACS570-Gittomcatmaven ec2-user]# git --version
git version 2.40.1
[root@Y21ACS570-Gittomcatmaven ec2-user]# ls -a
. .. .bash_history .bash_logout .bash_profile .bashrc .
ssh [root@Y21ACS570-Gittomcatmaven ec2-user]# mkdir
git_work [root@Y21ACS570-Gittomcatmaven ec2-user]# cd

1
4/4 B. Tech CSE Y21ACS570 DevOps Lab

git_work

2
4/4 B. Tech CSE Y21ACS570 DevOps Lab

[root@Y21ACS570-Gittomcatmaven git_work]# git


clone https://github.com/NailoSharu/u1.git
Cloning into 'u1'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3),
done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (3/3), done.
[root@Y21ACS570-Gittomcatmaven git_work]# git config --global
user.name NailoSharu
[root@Y21ACS570-Gittomcatmaven git_work]# git config --global
user.email [email protected]
[root@Y21ACS570-Gittomcatmaven git_work]# git config
--list user.name=NailoSharu
[email protected]
[root@Y21ACS570-Gittomcatmaven git_work]# ls -a
. .. u1
[root@Y21ACS570-Gittomcatmaven git_work]# cd u1
[root@Y21ACS570-Gittomcatmaven u1]# git add
README.md [root@Y21ACS570-Gittomcatmaven u1]#
git status
On branch main
Your branch is up to date with
'origin/main'. nothing to commit, working
tree clean [root@Y21ACS570-Gittomcatmaven
u1]# nano usecase1

3
4/4 B. Tech CSE Y21ACS570 DevOps Lab

[root@Y21ACS570-Gittomcatmaven u1]# git status


On branch main
Your branch is up to date with 'origin/main'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
usecase1
nothing added to commit but untracked files present (use "git
add" to track)
[root@Y21ACS570-Gittomcatmaven u1]# git add usecase1
[root@Y21ACS570-Gittomcatmaven u1]# git commit -m "usecase-1 commit"
[main e3269c9] usecase-1 commit
1 file changed, 1 insertion(+)
create mode 100644 usecase1
[root@Y21ACS570-Gittomcatmaven u1]# git push origin
main Username for 'https://github.com': NailoSharu
Password for 'https://[email protected]':
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 316 bytes | 316.00 KiB/s,
done. Total 3 (delta 0), reused 0 (delta 0), pack-
reused 0
To https://github.com/NailoSharu/u1.git
84eddce..e3269c9 main -> main

4
4/4 B. Tech CSE Y21ACS570 DevOps Lab

Exercise-2:
Execution of Git commands to create a local repository, update it, and push
changes to GitHub.

[root@Y21ACS570-Gittomcatmaven git_work]#
mkdir u2 [root@Y21ACS570-Gittomcatmaven
git_work]# cd u2 [root@Y21ACS570-
Gittomcatmaven u2]# git init
hint: Using 'master' as the name for the initial branch. This
default branch name
hint: is subject to change. To configure the initial branch name to
use in all
hint: of your new repositories, which will suppress this
warning, call: hint:
hint: git config --global init.defaultBranch
<name> hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk'
and
hint: 'development'. The just-created branch can be renamed via
this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in
/home/ec2-user/git_work/u2/.git/ [root@Y21ACS570-
Gittomcatmaven u2]# git branch -m master main [root@Y21ACS570-
Gittomcatmaven u2]# nano usecase2

5
4/4 B. Tech CSE Y21ACS570 DevOps Lab

[root@Y21ACS570-Gittomcatmaven u2]# ls -a
. .. .git usecase2
[root@Y21ACS570-Gittomcatmaven u2]# git add .
[root@Y21ACS570-Gittomcatmaven u2]# git commit -m "usecase-2 commit"
[main (root-commit) 58aa5e9] usecase-2 commit
1 file changed, 1 insertion(+)
create mode 100644 usecase2
[root@Y21ACS570-Gittomcatmaven u2]# git remote add
origin https://github.com/NailoSharu/usecase2.git
[root@Y21ACS570-Gittomcatmaven u2]# git push origin
main Username for 'https://github.com': NailoSharu
Password for 'https://[email protected]':
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 253 bytes | 253.00 KiB/s,
done. Total 3 (delta 0), reused 0 (delta 0), pack-
reused 0
To https://github.com/NailoSharu/usecase2.git
* [new branch] main -> main

6
4/4 B. Tech CSE Y21ACS570 DevOps Lab

Exercise-3:
Demonstration of Git commands to pull and fetch from remote repositories.
Git pull:
[root@Y21ACS570-Gittomcatmaven git_work]# mkdir developer-1
[root@Y21ACS570-Gittomcatmaven git_work]# cd developer-1
[root@Y21ACS570-Gittomcatmaven developer-1]# git
clone https://github.com/NailoSharu/usecase3.git
Cloning into 'usecase3'...
warning: You appear to have cloned an empty repository.
[root@Y21ACS570-Gittomcatmaven developer-1]# ls -a
. .. usecase3
[root@Y21ACS570-Gittomcatmaven developer-1]# cd
usecase3 [root@Y21ACS570-Gittomcatmaven usecase3]#
nano dev1

[root@Y21ACS570-Gittomcatmaven usecase3]# git add .


[root@Y21ACS570-Gittomcatmaven usecase3]# git commit -m
"developer-1 commit"
[main (root-commit) 6550452] developer-1 commit
1 file changed, 1 insertion(+)
create mode 100644 dev1
[root@Y21ACS570-Gittomcatmaven usecase3]# git push
origin main Username for 'https://github.com':
NailoSharu
Password for 'https://[email protected]':

7
4/4 B. Tech CSE Y21ACS570 DevOps Lab

Enumerating objects: 3, done.


Counting objects: 100% (3/3),
done.
Writing objects: 100% (3/3), 242 bytes | 242.00 KiB/s,
done. Total 3 (delta 0), reused 0 (delta 0), pack-
reused 0
To https://github.com/NailoSharu/usecase3.git
* [new branch] main -> main
[root@Y21ACS570-Gittomcatmaven usecase3]# cd ..
[root@Y21ACS570-Gittomcatmaven developer-1]# cd ..
[root@Y21ACS570-Gittomcatmaven git_work]# mkdir
developer-2 [root@Y21ACS570-Gittomcatmaven git_work]#
cd developer-2 [root@Y21ACS570-Gittomcatmaven
developer-2]# git init
hint: Using 'master' as the name for the initial branch. This
default branch name
hint: is subject to change. To configure the initial branch name to
use in all
hint: of your new repositories, which will suppress this
warning, call: hint:
hint: git config --global init.defaultBranch
<name> hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk'
and
hint: 'development'. The just-created branch can be renamed via
this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in
/home/ec2-user/git_work/developer- 2/.git/
[root@Y21ACS570-Gittomcatmaven developer-2]# git branch -m
master main [root@Y21ACS570-Gittomcatmaven developer-2]# nano
dev2

8
4/4 B. Tech CSE Y21ACS570 DevOps Lab

[root@Y21ACS570-Gittomcatmaven developer-2]# git remote add


origin https://github.com/NailoSharu/usecase3.git
[root@Y21ACS570-Gittomcatmaven developer-2]# git add .
[root@Y21ACS570-Gittomcatmaven developer-2]# git pull
origin main remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0 (from 0)
Unpacking objects: 100% (3/3), 222 bytes | 222.00 KiB/s, done.
From https://github.com/NailoSharu/usecase3
* branch main -> FETCH_HEAD
* [new branch] main -> origin/main
[root@Y21ACS570-Gittomcatmaven developer-2]# git commit -m "developer-
2 commit"
[main 81b4b07] developer-2 commit
1 file changed, 1
insertion(+) create mode
100644 dev2
[root@Y21ACS570-Gittomcatmaven developer-2]# git push origin main
Username for 'https://github.com': NailoSharu
Password for 'https://[email protected]':
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 297 bytes | 297.00 KiB/s,
done. Total 3 (delta 0), reused 0 (delta 0), pack-
reused 0
To https://github.com/NailoSharu/usecase3.git 6550452..81b4b07
main -> main

9
4/4 B. Tech CSE Y21ACS570 DevOps Lab

Git fetch and merge:


[root@Y21ACS570-Gittomcatmaven git_work]# mkdir fetch_opr
[root@Y21ACS570-Gittomcatmaven git_work]# cd fetch_opr
[root@Y21ACS570-Gittomcatmaven fetch_opr]# git clone
https://github.com/NailoSharu/fetch_operation.git
Cloning into 'fetch_operation'...
warning: You appear to have cloned an empty repository.
[root@Y21ACS570-Gittomcatmaven fetch_opr]# cd
fetch_operation [root@Y21ACS570-Gittomcatmaven
fetch_operation]# nano f1.txt

[root@Y21ACS570-Gittomcatmaven fetch_operation]# git add .


[root@Y21ACS570-Gittomcatmaven fetch_operation]# git commit -m
"local commit"
[main (root-commit) 35c69f0] local commit
1 file changed, 1
insertion(+) create mode
100644 f1.txt
[root@Y21ACS570-Gittomcatmaven fetch_operation]# git push origin main
Username for 'https://github.com': NailoSharu
Password for 'https://[email protected]':
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 227 bytes | 227.00 KiB/s,
done. Total 3 (delta 0), reused 0 (delta 0), pack-
reused 0

1
0
4/4 B. Tech CSE Y21ACS570 DevOps Lab

To https://github.com/NailoSharu/fetch_operation.git
* [new branch] main -> main
[root@Y21ACS570-Gittomcatmaven fetch_operation]# git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean

[root@Y21ACS570-Gittomcatmaven fetch_operation]# git fetch


remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4),
done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
Unpacking objects: 100% (3/3), 923 bytes | 923.00 KiB/s, done.
From https://github.com/NailoSharu/fetch_operation
35c69f0..bf8064d main -> origin/main
[root@Y21ACS570-Gittomcatmaven fetch_operation]# git status
On branch main
Your branch is behind 'origin/main' by 1 commit, and can be
fast- forwarded.

1
1
4/4 B. Tech CSE Y21ACS570 DevOps Lab

(use "git pull" to update your local branch)


nothing to commit, working tree clean
[root@Y21ACS570-Gittomcatmaven fetch_operation]# git merge
Updating
35c69f0..bf8064d Fast-
forward
f2.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 f2.txt
[root@Y21ACS570-Gittomcatmaven fetch_operation]# git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
[root@Y21ACS570-Gittomcatmaven fetch_operation]# git push origin main
Username for 'https://github.com': NailoSharu
Password for 'https://[email protected]':
Everything up-to-date

1
2
4/4 B. Tech CSE Y21ACS570 DevOps Lab

Exercise-4:
Demonstration of Git commands for merge, rebase, and resolving merge conflicts.

[root@Y21ACS570-Gittomcatmaven git_work]# mkdir m_r


[root@Y21ACS570-Gittomcatmaven git_work]# cd m_r
[root@Y21ACS570-Gittomcatmaven m_r]# git clone
https://github.com/NailoSharu/merge_rebase.git
Cloning into 'merge_rebase'...
remote: Enumerating objects: 3,
done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (3/3), done.
[root@Y21ACS570-Gittomcatmaven m_r]# cd merge_rebase
[root@Y21ACS570-Gittomcatmaven merge_rebase]# git checkout -b branch-1
Switched to a new branch 'branch-1'
[root@Y21ACS570-Gittomcatmaven merge_rebase]# nano file1

[root@Y21ACS570-Gittomcatmaven merge_rebase]# git add .


[root@Y21ACS570-Gittomcatmaven merge_rebase]# git commit -m "1st
commit"
[branch-1 cd79100] 1st commit
1 file changed, 1 insertion(+)
create mode 100644 file1

1
3
4/4 B. Tech CSE Y21ACS570 DevOps Lab

[root@Y21ACS570-Gittomcatmaven merge_rebase]# git log --graph


* commit cd79100ca90616b8de6c2ca829f79ca243a05ba5 (HEAD -> branch-1)
| Author: NailoSharu <[email protected]>
| Date: Sun Dec 15 06:23:31 2024 +0000
|
| 1st commit
|
* commit e1c4f720426dbc0a08ada664dc330fa21746427d
(origin/main, origin/HEAD, main)
Author: NailoSharu <[email protected]>
Date: Sun Dec 15 11:52:21 2024 +0530

Initial commit
[root@Y21ACS570-Gittomcatmaven merge_rebase]# git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
[root@Y21ACS570-Gittomcatmaven merge_rebase]# git merge branch-1
Updating
e1c4f72..cd79100 Fast-
forward
file1 | 1 +
1 file changed, 1 insertion(+)
create mode 100644 file1
[root@Y21ACS570-Gittomcatmaven merge_rebase]# git push origin main
Username for 'https://github.com': NailoSharu
Password for 'https://[email protected]':
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 293 bytes | 293.00 KiB/s,
done. Total 3 (delta 0), reused 0 (delta 0), pack-
reused 0
To https://github.com/NailoSharu/merge_rebase.git
e1c4f72..cd79100 main -> main
1
4
4/4 B. Tech CSE Y21ACS570 DevOps Lab

[root@Y21ACS570-Gittomcatmaven merge_rebase]# git checkout


branch-2 error: pathspec 'branch-2' did not match any file(s)
known to git [root@Y21ACS570-Gittomcatmaven merge_rebase]# git
checkout -b branch-2 Switched to a new branch 'branch-2'
[root@Y21ACS570-Gittomcatmaven merge_rebase]# nano file2

[root@Y21ACS570-Gittomcatmaven merge_rebase]# git add .


[root@Y21ACS570-Gittomcatmaven merge_rebase]# git commit -m "2nd
commit"
[branch-2 de7066e] 2nd commit
1 file changed, 1 insertion(+)
create mode 100644 file2
[root@Y21ACS570-Gittomcatmaven merge_rebase]# git log --graph
* commit de7066ecbcaf5ac4f73ce2d0bdd869c1f169b610 (HEAD -> branch-2)
| Author: NailoSharu <[email protected]>
| Date: Sun Dec 15 06:25:18 2024 +0000
|
| 2nd commit
|
* commit cd79100ca90616b8de6c2ca829f79ca243a05ba5
(origin/main, origin/HEAD, main, branch-1)
| Author: NailoSharu <[email protected]>
| Date: Sun Dec 15 06:23:31 2024 +0000
|

1
5
4/4 B. Tech CSE Y21ACS570 DevOps Lab

| 1st commit
|
* commit e1c4f720426dbc0a08ada664dc330fa21746427d
Author: NailoSharu <[email protected]>
Date: Sun Dec 15 11:52:21 2024 +0530

Initial commit
[root@Y21ACS570-Gittomcatmaven merge_rebase]# git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
[root@Y21ACS570-Gittomcatmaven merge_rebase]# git rebase branch-2
Successfully rebased and updated refs/heads/main.
[root@Y21ACS570-Gittomcatmaven merge_rebase]# git push origin main
Username for 'https://github.com': NailoSharu
Password for 'https://[email protected]':
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 319 bytes | 319.00 KiB/s,
done. Total 3 (delta 0), reused 0 (delta 0), pack-
reused 0
To https://github.com/NailoSharu/merge_rebase.git
cd79100..de7066e main -> main

1
6
4/4 B. Tech CSE Y21ACS570 DevOps Lab

Exercise-5:
Creation of an EC2 instance and installation and configuration of Git, JDK,
Maven, and Tomcat. Creation of a maven application and packaging.

Step 1: sign in to AWS management console

Step 2: Open EC2 Dashboard


o Click on EC2 under “services”

1
7
4/4 B. Tech CSE Y21ACS570 DevOps Lab

Step 3: Launch an EC2 Instance


o In the EC2 Dashboard, click the Launch instance button.

Step 4: Configure Instance Details


1. Name and Application and OS images:
o Enter a name for your EC2 instance
o Select Amazon Linux under the Free tier eligible section

1
8
4/4 B. Tech CSE Y21ACS570 DevOps Lab

2. Instance Type:
o Choose the instance type as t2.micro

3. Key pair
o Create a new key pair(or select an existing one). Download the key pair (with .pem
extension) and store it securely, as it will be required for SSH access.

4. Network settings
o Leave the default settings (or customize as needed). Ensure allow SSH traffic from is
selected
o Click on Launch instance

1
9
4/4 B. Tech CSE Y21ACS570 DevOps Lab

2
0
4/4 B. Tech CSE Y21ACS570 DevOps Lab

Installing GIT:

[ec2-user@Y21ACS570-Jenkins ~]$ sudo su


[root@Y21ACS570-Jenkins ec2-user]# sudo yum install git -y
Last metadata expiration check: 0:01:15 ago on Sun Dec 15 08:34:37
2024. Dependencies resolved.
=======================================================================
===
==================================================================
Package Architecture
Version Repository Size
=======================================================================
===
==================================================================
Installing:
git x86_64 2.40.1-
1.amzn2023.0.3 amazonlinux 54 k
.
.
.
Complete!

Installing JDK:

[root@Y21ACS570-Gittomcatmaven ec2-user]# sudo yum install java-17-


amazon- corretto-devel -y
Last metadata expiration check: 3:50:17 ago on Sun Dec 15 04:56:07
2024. Dependencies resolved.
=======================================================================
===
==================================================================
Package Architecture Version
Repository Size
=======================================================================
===
==================================================================
Installing:
java-17-amazon-corretto-devel x86_64
1:17.0.13+11-1.amzn2023.1 amazonlinux 142 k
.
.
libjpeg-turbo-2.1.4-
2.amzn2023.0.5.x86_64 libpng-
2:1.6.37-10.amzn2023.0.6.x86_64
libxcb-1.17.0-1.amzn2023.0.1.x86_64
pixman-0.43.4-1.amzn2023.0.4.x86_64
xml-common-0.6.3-56.amzn2023.0.2.noarch
.
.
Complete!
2
1
4/4 B. Tech CSE Y21ACS570 DevOps Lab

[root@Y21ACS570-Gittomcatmaven ec2-user]# nano .bashrc

2
2
4/4 B. Tech CSE Y21ACS570 DevOps Lab

[root@Y21ACS570-Gittomcatmaven ec2-user]# source


.bashrc [root@Y21ACS570-Gittomcatmaven ec2-user]#
sudo su - Last login: Sun Dec 15 08:39:22 UTC 2024
on pts/1 [root@Y21ACS570-Gittomcatmaven ~]#
nano .bashrc

[root@Y21ACS570-Gittomcatmaven ~]# source


.bashrc [root@Y21ACS570-Gittomcatmaven ~]#
logout
[root@Y21ACS570-Gittomcatmaven ec2-user]# javac -version
javac 17.0.13

Installing Tomcat:

[ec2-user@Y21ACS570-Gittomcatmaven ~]$ sudo


su [root@Y21ACS570-Gittomcatmaven ec2-user]#
cd /opt [root@Y21ACS570-Gittomcatmaven opt]#
wget
https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.98/bin/apache-tomcat-
9.0.98.tar.gz
--2024-12-15 08:40:23--
https://dlcdn.apache.org/tomcat/tomcat-
9/v9.0.98/bin/apache-tomcat-9.0.98.tar.gz
Resolving dlcdn.apache.org (dlcdn.apache.org)... 151.101.2.132,
2a04:4e42::644
Connecting to dlcdn.apache.org (dlcdn.apache.org)|
151.101.2.132|:443... connected.
2
3
4/4 B. Tech CSE Y21ACS570 DevOps Lab

HTTP request sent, awaiting response... 200 OK


Length: 12760610 (12M) [application/x-gzip]

2
4
4/4 B. Tech CSE Y21ACS570 DevOps Lab

Saving to: ‘apache-tomcat-9.0.98.tar.gz’

apache-tomcat-9.0.98.tar.gz 100%
[================================================================>]
12.17M --.-KB/s in 0.1s

2024-12-15 08:40:24 (89.6 MB/s) - ‘apache-tomcat-9.0.98.tar.gz’ saved


[12760610/12760610]

[root@Y21ACS570-Gittomcatmaven opt]# tar -xvzf apache-tomcat-


9.0.98.tar.gz
apache-tomcat-9.0.98/conf/
apache-tomcat-9.0.98/conf/catalina.policy
apache-tomcat-9.0.98/conf/catalina.proper
ties
.
.
pache-tomcat-9.0.98/bin/shutdown.sh
apache-tomcat-9.0.98/bin/startup.sh
apache-tomcat-9.0.98/bin/tool-
wrapper.sh
apache-tomcat-9.0.98/bin/version.sh
[root@Y21ACS570-Gittomcatmaven opt]# mv apache-tomcat-9.0.98
tomcat [root@Y21ACS570-Gittomcatmaven opt]# ln -s
/opt/tomcat/bin/startup.sh
/usr/bin/tomcat-start
[root@Y21ACS570-Gittomcatmaven opt]# ln -s /opt/tomcat/bin/shutdown.sh
/usr/bin/tomcat-stop
[root@Y21ACS570-Gittomcatmaven opt]# find -name context.xml
./tomcat/conf/context.xml
./tomcat/webapps/docs/META-INF/context.xml
./tomcat/webapps/examples/META-INF/context.xml
./tomcat/webapps/host-manager/META-INF/context.xml
./tomcat/webapps/manager/META-INF/context.xml
[root@Y21ACS570-Gittomcatmaven opt]# nano
./tomcat/webapps/host- manager/META-INF/context.xml

[root@Y21ACS570-Gittomcatmaven opt]# nano


./tomcat/webapps/manager/META- INF/context.xml

2
5
4/4 B. Tech CSE Y21ACS570 DevOps Lab

[root@Y21ACS570-Gittomcatmaven opt]# find -name tomcat-users.xml


./tomcat/conf/tomcat-users.xml
[root@Y21ACS570-Gittomcatmaven opt]# nano ./tomcat/conf/tomcat-
users.xml

[root@Y21ACS570-Gittomcatmaven ec2-user]# tomcat-start


Using CATALINA_BASE: /opt/tomcat
Using CATALINA_HOME: /opt/tomcat
Using CATALINA_TMPDIR:
/opt/tomcat/temp
Using JRE_HOME: /usr/lib/jvm/java-17-amazon-
corretto Using CLASSPATH:
/opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-
juli.jar Using CATALINA_OPTS:
Tomcat started.

2
6
4/4 B. Tech CSE Y21ACS570 DevOps Lab

2
7
4/4 B. Tech CSE Y21ACS570 DevOps Lab

Installing Maven:
[root@Y21ACS570-Gittomcatmaven ec2-user]# cd
/opt [root@Y21ACS570-Gittomcatmaven opt]#
wget
https://dlcdn.apache.org/maven/maven-3/3.9.9/binaries/apache-maven-
3.9.9- bin.tar.gz
--2024-12-15 09:23:00--
https://dlcdn.apache.org/maven/maven-
3/3.9.9/binaries/apache-maven-3.9.9-bin.tar.gz
Resolving dlcdn.apache.org (dlcdn.apache.org)... 151.101.2.132,
2a04:4e42::644
Connecting to dlcdn.apache.org (dlcdn.apache.org)|
151.101.2.132|:443... connected.
HTTP request sent, awaiting response... 200 OK
.
.
2024-12-15 09:23:00 (92.4 MB/s) - ‘apache-maven-3.9.9-bin.tar.gz’
saved [9102945/9102945]
[root@Y21ACS570-Gittomcatmaven opt]# tar -xvzf apache-maven-
3.9.9- bin.tar.gz
apache-maven-3.9.9/
README.txt apache-maven-
3.9.9/LICENSE apache-
maven-3.9.9/NOTICE
.
.
apache-maven-3.9.9/lib/maven-resolver-connector-basic-
1.9.22.jar apache-maven-3.9.9/lib/plexus-utils-3.5.1.jar
[root@Y21ACS570-Gittomcatmaven opt]# mv apache-maven-3.9.9
maven [root@Y21ACS570-Gittomcatmaven opt]# cd /home/ec2-
user [root@Y21ACS570-Gittomcatmaven ec2-user]#
nano .bashrc

[root@Y21ACS570-Gittomcatmaven ec2-user]# source


.bashrc [root@Y21ACS570-Gittomcatmaven ec2-user]#
sudo su - Last login: Sun Dec 15 08:47:37 UTC 2024
on pts/2 [root@Y21ACS570-Gittomcatmaven ~]#
2
8
4/4 B. Tech CSE Y21ACS570 DevOps Lab

nano .bashrc

2
9
4/4 B. Tech CSE Y21ACS570 DevOps Lab

[root@Y21ACS570-Gittomcatmaven ~]# source


.bashrc [root@Y21ACS570-Gittomcatmaven ~]#
logout
[root@Y21ACS570-Gittomcatmaven ec2-user]# mvn -version
Apache Maven 3.9.9
(8e8579a9e76f7d015ee5ec7bfcdc97d260186937) Maven
home: /opt/maven
Java version: 17.0.13, vendor: Amazon.com Inc., runtime:
/usr/lib/jvm/java-17-amazon-corretto.x86_64
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "6.1.115-126.197.amzn2023.x86_64",
arch: "amd64", family: "unix"

Creating a Maven web application:

[root@Y21ACS570-Gittomcatmaven ec2-user]# mvn archetype:generate -


DgroupId=Devops.ex -DartifactId=sample-webapp -
DarchetypeArtifactId=maven- archetype-webapp -
DinteractiveMode=false
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom
>-------------- [INFO] Building Maven Stub Project (No POM) 1
[INFO] [ pom ]
[INFO]
[INFO] >>> archetype:3.3.1:generate (default-cli) > generate-
sources @ standalone-pom >>>
.
.
[INFO]
[INFO] BUILD SUCCESS
[INFO]
[INFO] Total time: 2.573 s
[INFO] Finished at: 2024-12-15T10:02:24Z
[root@Y21ACS570-Gittomcatmaven ec2-user]# ls -a

3
0
4/4 B. Tech CSE Y21ACS570 DevOps Lab

. .. .bash_history .bash_logout .bash_profile .bashrc .ssh git_work


sample-webapp
[root@Y21ACS570-Gittomcatmaven ec2-user]# cd sample-
webapp [root@Y21ACS570-Gittomcatmaven sample-webapp]#
mvn package [INFO] Scanning for projects...
[INFO]
[INFO] < Devops.ex:sample-
webapp > [INFO] Building sample-webapp Maven Webapp
1.0-SNAPSHOT [INFO] from pom.xml
[INFO] [ war ]
[INFO]
[INFO] --- resources:3.3.1:resources (default-resources) @ sample-
webapp - [WARNING] Using platform encoding (UTF-8 actually) to copy
filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource from src/main/resources to target/classes
.
.
[INFO] Building war: /home/ec2-user/sample-webapp/target/sample-
webapp.war [INFO]

[INFO] BUILD SUCCESS


[INFO]
[INFO] Total time: 2.523 s
[INFO] Finished at: 2024-12-15T10:03:46Z
[INFO]
[root@Y21ACS570-Gittomcatmaven sample-webapp]# cp
./target/sample- webapp.war /opt/tomcat/webapps
[root@Y21ACS570-Gittomcatmaven sample-webapp]# tomcat-start
Using CATALINA_BASE: /opt/tomcat
Using CATALINA_HOME: /opt/tomcat
Using CATALINA_TMPDIR:
/opt/tomcat/temp
Using JRE_HOME: /usr/lib/jvm/java-17-amazon-
corretto Using CLASSPATH:
/opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-
juli.jar Using CATALINA_OPTS:
Tomcat started.

3
1
4/4 B. Tech CSE Y21ACS570 DevOps Lab

Exercise-6:
Create and push maven application using Eclipse, install Jenkins, build the
application using Jenkins plugins and host it on Tomcat.

1. Open Start menu -> Search for Eclipse -> Click Eclipse IDE forEnterprise Java
and WebDevelopers.

2. Set your path as default workspace then click on Launch button.

3. Create a new Maven Project using menu File -> New -> Maven Project

3
2
4/4 B. Tech CSE Y21ACS570 DevOps Lab

4. In New Maven Project Popup window choose the following settings


o Use default Workspace location -> Click on Next Button

o Choose ArchetypeID as maven-archetype-webapp then Click on NextButton


Provide Group Id and Artifact Id and click on finish button

3
3
4/4 B. Tech CSE Y21ACS570 DevOps Lab

5. Running the application on the server


o Open file menu -> go to Run As -> select Run on Server

o Enable (Radio button) Manually define a new server -> select apache ->
selectTomcat v9.0 Server -> click on next

3
4
4/4 B. Tech CSE Y21ACS570 DevOps Lab

o Specify the location where you have downloaded the Tomcatwindows (64 bit)
version and click on finish.

3
5
4/4 B. Tech CSE Y21ACS570 DevOps Lab

6. Uploading the Created Project to the GitHub


a. Right click on Project -> Team -> Share Project

b. Enable the checkbox (use or create repository in parent folder ofproject) andselect the
path and click on finish.

3
6
4/4 B. Tech CSE Y21ACS570 DevOps Lab

c. Right click on the project -> Team -> Commit

d. Click on add all files including not selected ones to the index and click on commit

3
7
4/4 B. Tech CSE Y21ACS570 DevOps Lab

e. Click on push HEAD

f. Provide the URI and click on preview

3
8
4/4 B. Tech CSE Y21ACS570 DevOps Lab

g. Change the branch from master to main and click on preview andnextclick on push

h. Provide the credentials and click on Log in

3
9
4/4 B. Tech CSE Y21ACS570 DevOps Lab

Installing and configuring Jenkins:


[root@Y21ACS570-jenkins ec2-user]# wget -O
/etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-
stable/jenkins.repo
--2024-09-29 09:16:47--
https://pkg.jenkins.io/redhat-stable/jenkins.repo Resolving
pkg.jenkins.io (pkg.jenkins.io). ..... 151.101.154.133,
2a04:4e42:24::645 Connecting to pkg.jenkins.io (pkg.jenkins.io)|
151.101.154.133|:443... connected. HTTP request sent, awaiting
response... 200 OK Length: 85 Saving to:
‘/etc/yum.repos.d/jenkins.repo’ /etc/yum.repos.d/jenkins.repo 100%
[=====================================================>] 85 - -.- KB/s
in 0s 2024-09-29 09:16:47 (3.12 MB/s) -
‘/etc/yum.repos.d/jenkins.repo’ saved [85/85]
[root@Y21ACS570-jenkins ec2-user]# rpm -- import
https://pkg.jenkins.io/redhat-stable/jenkins.io-
2023.key [root@Y21ACS570-jenkins ec2-user]# yum
install jenkins -y
Jenkins-stable 296 kB/s | 29 kB 00:00 Last metadata expiration check:
.
.
.
Version Repository Size
=======================================================================
===
= =================================================== Installing:
jenkins
noarch 2.462.2-1.1 jenkins 89 M . . . Installed: jenkins-2.462.2-
1.1. noarch Complete!
[root@Y21ACS570-jenkins ec2-user]# service jenkins start
Redirecting to /bin/systemctl start jenkins.service

a. Access Jenkins
Open Jenkins in your browser: http://<public ip>:8080 and copy the path

[root@Y21ACS570-jenkins ec2-user]# cat


4
0
4/4 B. Tech CSE Y21ACS570 DevOps Lab

/var/lib/jenkins/secrets/initialAdminPassword
3a67bb92b9b54a29aa045741adfa51b3

4
1
4/4 B. Tech CSE Y21ACS570 DevOps Lab

b. Click on continue and click on select plugins to install

c. Uncheck all the checkboxes (click on None) and click on install

d. create your own userid and password for Jenkins login.

4
2
4/4 B. Tech CSE Y21ACS570 DevOps Lab

e. Click on Start using Jenkins

Installing Github and Maven plugin and configuring JDK, Git and Maven usingTools Button
in Manage Jenkins Tab:

a. Goto Dashboard -> Manage Jenkins -> plugins -> available plugins -> search for GitHub ->
select the first one -> click on install

b. Again, search for maven integration -> select the first one -> click oninstall

4
3
4/4 B. Tech CSE Y21ACS570 DevOps Lab

c. Goto to Dashboard -> Manage Jenkins -> Tools -> Add JDK

d. Specify the name in Git section

4
4
4/4 B. Tech CSE Y21ACS570 DevOps Lab

e. Specify the name in maven section and uncheck the checkbox (install
automatically) andprovide the path and click on apply and then click on save

Creating a new job:

a. Goto Dashboard -> all -> New Item and choose maven project and clickon ok

4
5
4/4 B. Tech CSE Y21ACS570 DevOps Lab

b. Provide the description and scroll down

c. In SCM choose Git and provide the URL of GitHub repo. at repository URLand scroll down

4
6
4/4 B. Tech CSE Y21ACS570 DevOps Lab

d. In branches to build change branch specifier from master to main and scroll down and in
goals and options type "clean install”and scroll down

e. Click on Apply and then click on save

4
7
4/4 B. Tech CSE Y21ACS570 DevOps Lab

f. Goto Dashboard -> Nodes -> built-in Node -> configure -> Disk space monitoring thresholds
-> mark all the values as 0 -> click on save

g. Click on Build Now and check console output

4
8
4/4 B. Tech CSE Y21ACS570 DevOps Lab

DEPLOYMENT:
Go to EC2-instances start the tomcat instance
a. Go back to Dashboard -> Manage jenkins -> Plugins -> Available pluginsSearch for publish
over SSH

b. Go to Dashboard -> manage jenkins -> Click on system -> publish overSSH -> click on add -
> provide the following
Name: TomcatServer
Hostname: private ip of instance where tomcat is installed
Username: ec2-user

4
9
4/4 B. Tech CSE Y21ACS570 DevOps Lab

c. After providing, expand the Advanced section -> enable the checkbox(use password
authentication or use a different key) Goto file explorer and search for the .pem file of
tomcat instance and make areplica of it. Now open it in any editor copy it and paste it in
keysection

d. After pasting scroll down at last you’ll see test configuration click on it theoutput should be
success which should be displayed on the left sideof yourpage and after successful
outcome click on apply and then click on save

5
0
4/4 B. Tech CSE Y21ACS570 DevOps Lab

Now to the terminal where tomcat had installed


[ec2-user@Y21ACS570-Gittomcatmaven ~]$ sudo su
[root@Y21ACS570-Gittomcatmaven ec2-user]# tomcat-
start Using CATALINA_BASE: /opt/tomcat
Using CATALINA_HOME: /opt/tomcat
Using CATALINA_TMPDIR:
/opt/tomcat/temp
Using JRE_HOME: /usr/lib/jvm/java-17-amazon-
corretto Using CLASSPATH:
/opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-
juli.jar Using CATALINA_OPTS:
Tomcat started.
[root@Y21ACS570-Gittomcatmaven ec2-user]# usermod -aG root ec2-user
[root@Y21ACS570-Gittomcatmaven ec2-user]# chmod -R g+w
/opt/tomcat/webapps

e. Go to Dashboard -> open the same item -> configure -> scroll down to post-build actions ->
add post-build action -> send build artfact over SSH

5
1
4/4 B. Tech CSE Y21ACS570 DevOps Lab

f. Scroll down to Transfer Set and specify the following


Source files: target/*war
Remove prefix: target/
Remote directory: //opt//tomcat//webapps
Click on apply and then click on save

g. Now Build it again and check the console output

5
2
4/4 B. Tech CSE Y21ACS570 DevOps Lab

AUTOMATION:

a. Goto the created item -> configure -> Build Triggers -> enable the checkbox
(poll SCM) and type the following in schedule * * * * *
Click on apply and then click on save

b. Back to the job and build it again using Build Now and check the consoleoutput

5
3
4/4 B. Tech CSE Y21ACS570 DevOps Lab

Making changes and automate the build

5
4
4/4 B. Tech CSE Y21ACS570 DevOps Lab

Exercise-7:
Demonstration of containerization using Docker.

1. Pulling docker image already exists in docker hub into the machine

[ec2-user@Y21ACS570-dockerhost ~]$ sudo su


[root@Y21ACS570-dockerhost ec2-user]# sudo yum install docker -y
Last metadata expiration check: 0:02:43 ago on Sun Dec 15 22:45:50
2024. Dependencies resolved.
=======================================================================
===
==================================================================
Package Architecture
Version Repository Size
.
.
.
libnfnetlink-1.0.1-19.amzn2023.0.2.x86_64 libnftnl-
1.2.2- 2.amzn2023.0.2.x86_64 pigz-2.5-
1.amzn2023.0.3.x86_64
runc-1.1.14-1.amzn2023.0.1.x86_64

Complete!
[root@Y21ACS570-dockerhost ec2-user]# service docker
start Redirecting to /bin/systemctl start
docker.service [root@Y21ACS570-dockerhost ec2-user]#
docker images REPOSITORY TAG IMAGE ID
CREATED SIZE
[root@Y21ACS570-dockerhost ec2-user]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@Y21ACS570-dockerhost ec2-user]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@Y21ACS570-dockerhost ec2-user]# docker pull tomcat
Using default tag: latest
latest: Pulling from
library/tomcat de44b265507a: Pull
complete 4c2afd91a87d: Pull
complete 89e9bbcfa697: Pull
complete 11be3e613582: Pull
complete 1b9d1e181a2a: Pull
complete a923f560618a: Pull
complete 4f4fb700ef54: Pull
complete cb2453413e93: Pull
complete
Digest:
sha256:935ff51abecc8dc793cb19c229ac7a988c8899e5fcba5e69ae96530fa7
6c4d56 Status: Downloaded newer image for tomcat:latest
docker.io/library/tomcat:latest
[root@Y21ACS570-dockerhost ec2-user]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
5
5
4/4 B. Tech CSE Y21ACS570 DevOps Lab

tomcat latest f62f518e5c5c 6 days ago 467MB

5
6
4/4 B. Tech CSE Y21ACS570 DevOps Lab

[root@Y21ACS570-dockerhost ec2-user]# docker run -d --name


tomcat- container -p 8081:8080 tomcat
f0cfdcc3d9f910a5c402a5bc413af4c1a1e7ba0a4943c9d4186600a5af9bd
7de [root@Y21ACS570-dockerhost ec2-user]# docker ps
CONTAINER ID IMAGE COMMAND CREATED
STATUS PORTS NAMES
f0cfdcc3d9f9 tomcat "catalina.sh run" 6 seconds ago Up 5
seconds 0.0.0.0:8081->8080/tcp, :::8081->8080/tcp tomcat-
container [root@Y21ACS570-dockerhost ec2-user]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED
STATUS PORTS NAMES
f0cfdcc3d9f9 tomcat "catalina.sh run" 9 seconds ago Up 8
seconds 0.0.0.0:8081->8080/tcp, :::8081->8080/tcp tomcat-
container [root@Y21ACS570-dockerhost ec2-user]# docker start
tomcat-container tomcat-container
[root@Y21ACS570-dockerhost ec2-user]# docker exec -it tomcat-container
/bin/bash
root@f0cfdcc3d9f9:/usr/local/tomcat# ls -l
webapps total 0
root@f0cfdcc3d9f9:/usr/local/tomcat# cp -r webapps.dist/* webapps
root@f0cfdcc3d9f9:/usr/local/tomcat# ls -l webapps
total 32
drwxr-xr- 16 root root 16384 Dec 15 22:51 docs
x.
drwxr-xr- 7 root root 99 Dec 15 22:51 examples
x.
drwxr-xr- 6 root root 79 Dec 15 22:51 host-
x. manager
drwxr-xr- 6 root root 114 Dec 15 22:51 manager
x.
drwxr-xr- 3 root root 16384 Dec 15 22:51 ROOT
x.
root@f0cfdcc3d9f9:/usr/local/
tomcat# exit

5
7
4/4 B. Tech CSE Y21ACS570 DevOps Lab

2. Creating a Dockerfile on your own and it is used to build an image.

[root@Y21ACS570-dockerhost ec2-user]# nano Dockerfile

[root@Y21ACS570-dockerhost ec2-user]# docker build -t mtomcat .


[+] Building 1.4s (6/6) FINISHED
docker:default
=> [internal] load build definition from
Dockerfile 0.1s
=> => transferring dockerfile:
184B 0.0s
=> [internal] load metadata for
docker.io/library/tomcat:latest 0.0s
=> [internal] load .dockerignore
0.0s
=> => transferring context: 2B
0.0s
=> [1/2] FROM
docker.io/library/tomcat:latest 0.2s
=> [2/2] RUN cp -R /usr/local/tomcat/webapps.dist/*
/usr/local/tomcat/
webapps 0.3s
=> exporting to
image 0.7s
=> => exporting
layers 0.7s
=> => writing image
sha256:6a738f191c049f0eccc20e211f0ffd1af19b14a0169b824a8f893b5a26
6636dc 0.0s
=> => naming to
docker.io/library/mtomcat 0.0s
[root@Y21ACS570-dockerhost ec2-user]# docker run -d --name
mtomcat- container -p 8082:8080 mtomcat
130c6271b4429f89cfb8c819864b5d2afc078dea57fc37b16a9cf05f7da28fc
d [root@Y21ACS570-dockerhost ec2-user]# docker start mtomcat-
container mtomcat-container

5
8
4/4 B. Tech CSE Y21ACS570 DevOps Lab

5
9
4/4 B. Tech CSE Y21ACS570 DevOps Lab

Exercise-8:
Implementation of Docker CI/CD pipeline using Jenkins.
[root@Y21ACS570-dockerhost ec2-user]# useradd
dockeradmin [root@Y21ACS570-dockerhost ec2-user]#
passwd dockeradmin Changing password for user
dockeradmin.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@Y21ACS570-dockerhost ec2-user]# usermod -aG docker
dockeradmin [root@Y21ACS570-dockerhost ec2-user]# nano
/etc/ssh/sshd_config

[root@Y21ACS570-dockerhost ec2-user]# service sshd


reload Redirecting to /bin/systemctl reload
sshd.service [root@Y21ACS570-dockerhost ec2-user]#
cd /opt [root@Y21ACS570-dockerhost opt]# mkdir
docker [root@Y21ACS570-dockerhost opt]# ls -l
total 0
drwxr-xr-x. 4 root root 33 Nov 22 05:03 aws
drwx--x--x. 4 root root 28 Dec 15 22:48 containerd
drwxr-xr-x. 2 root root 6 Dec 15 23:09 docker
[root@Y21ACS570-dockerhost opt]# chown -R dockeradmin:dockeradmin
docker [root@Y21ACS570-dockerhost opt]# ls -l
total 0
drwxr-xr-x. 4 root root 33 Nov 22 05:03 aws
drwx--x--x. 4 root root 28 Dec 15 22:48 containerd
drwxr-xr-x. 2 dockeradmin dockeradmin 6 Dec 15 23:09 docker
[root@Y21ACS570-dockerhost opt]# cd docker
[root@Y21ACS570-dockerhost docker]# nano
Dockerfile

6
0
4/4 B. Tech CSE Y21ACS570 DevOps Lab

Start Jenkins instance and do the following…


a. Add DockerHost and expand Advanced and provide the password.

Before testing the configuration make sure that Docker and Jenkins arestarted. Test the
configuration…

6
1
4/4 B. Tech CSE Y21ACS570 DevOps Lab

Creating a New Item from the existing…

6
2
4/4 B. Tech CSE Y21ACS570 DevOps Lab

a. Scroll down to bottom (post build actions) and edit the


following… Source files: target/*.war
Remove prefix: target
Remote Directory: //opt//docker

b. Build the Item and check the console Output

Run on browser

6
3
4/4 B. Tech CSE Y21ACS570 DevOps Lab

Exercise-9:
Demonstration of Docker CI/CD pipeline using Jenkins and Ansible.
Start the Ansible, Docker, jenkins instances
In ansible instance:
[ec2-user@Y21ACS570-ansiblehost ~]$ sudo su
[root@Y21ACS570-ansiblehost ec2-user]# sudo yum install ansible -y
Last metadata expiration check: 0:01:50 ago on Sun Dec 15 23:33:35
2024. Dependencies resolved.
=======================================================================
===
===============================================================
===
Package Architecture Version
Repository Size
.
.
.
Installed:
ansible-8.3.0-1.amzn2023.0.1.noarch ansible-core-
2.15.3- 1.amzn2023.0.4.x86_64 git-core-2.40.1-
1.amzn2023.0.3.x86_64
sshpass-1.09-6.amzn2023.0.1.x86_64
Complete!
[root@Y21ACS570-ansiblehost ec2-user]# useradd
ansadmin [root@Y21ACS570-ansiblehost ec2-user]#
passwd ansadmin Changing password for user
ansadmin.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@Y21ACS570-ansiblehost ec2-user]# visudo

[root@Y21ACS570-ansiblehost ec2-user]# nano /etc/ssh/sshd_config

6
4
4/4 B. Tech CSE Y21ACS570 DevOps Lab

[root@Y21ACS570-ansiblehost ec2-user]# service sshd reload


Redirecting to /bin/systemctl reload sshd.service
In docker instance:
[root@Y21ACS570-dockerhost ec2-user]# useradd
ansadmin [root@Y21ACS570-dockerhost ec2-user]#
passwd ansadmin Changing password for user
ansadmin.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@Y21ACS570-dockerhost ec2-user]# visudo

[root@Y21ACS570-dockerhost ec2-user]# nano /etc/ssh/sshd_config

6
5
4/4 B. Tech CSE Y21ACS570 DevOps Lab

[root@Y21ACS570-dockerhost ec2-user]# service sshd reload


Redirecting to /bin/systemctl reload sshd.service

In ansible instance:

[root@Y21ACS570-ansiblehost ec2-user]# sudo su -


ansadmin Last login: Sun Dec 15 23:46:07 UTC 2024 on
pts/2 [ansadmin@Y21ACS570-ansiblehost ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key
(/home/ansadmin/.ssh/id_rsa): Created directory
'/home/ansadmin/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in
/home/ansadmin/.ssh/id_rsa Your public key has been saved
in /home/ansadmin/.ssh/id_rsa.pub The key fingerprint is:
SHA256:zXUqSypzAWwbkRbmKpQLz1EG0Kn0pp1FRXn0sAq8MYg ansadmin@Y21ACS570-
ansiblehost
The key's randomart image is:
+---[RSA 3072]- -+
|.o.oo *=oo |
| .++o=oo .+ |
|oE=..**........|
|.= = +=+.o . o |
| O +...S = . |
| . + + o |
| o o . |
| + |
| |
+----[SHA256]- - -+
[root@Y21ACS570-ansiblehost ec2-user]# nano /etc/ansible/hosts

[ansadmin@Y21ACS570-ansiblehost ~]$ ssh-copy-id 172.31.2.115


/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed:
"/home/ansadmin/.ssh/id_rsa.pub"
The authenticity of host '172.31.2.115 (172.31.2.115)' can't be
established.
ED25519 key fingerprint is
SHA256:wcjUC2gAX2ahtDEyXREvUFyvOBO+Rxn/jQSTXgJTMVQ.

6
6
4/4 B. Tech CSE Y21ACS570 DevOps Lab

This key is not known by any other names


Are you sure you want to continue connecting (yes/no/[fingerprint])?
yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s),
to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you
are prompted now it is to install the new keys
[email protected]'s password:

Number of key(s) added: 1

Now try logging into the machine, with: "ssh '172.31.2.115'"


and check to make sure that only the key(s) you wanted were added.

[ansadmin@Y21ACS570-ansiblehost ~]$ sudo yum install docker -y


We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

#1) Respect the privacy of


others. #2) Think before you
type.
#3) With great power comes great responsibility.

For security reasons, the password you type will not be

visible. [sudo] password for ansadmin:


Last metadata expiration check: 0:15:51 ago on Sun Dec 15 23:33:35
2024. Dependencies resolved.
=======================================================================
===
==================================================================
Package Architecture
Version Repository Size
.
.
libnfnetlink-1.0.1-19.amzn2023.0.2.x86_64 libnftnl-
1.2.2- 2.amzn2023.0.2.x86_64 pigz-2.5-
1.amzn2023.0.3.x86_64
runc-1.1.14-1.amzn2023.0.1.x86_64

Complete!
[ansadmin@Y21ACS570-ansiblehost ~]$ sudo usermod -aG docker
ansadmin [ansadmin@Y21ACS570-ansiblehost ~]$ id ansadmin
uid=1001(ansadmin) gid=1001(ansadmin)
groups=1001(ansadmin),992(docker)
[ansadmin@Y21ACS570-ansiblehost ~]$ cd /opt
[ansadmin@Y21ACS570-ansiblehost opt]$ sudo mkdir
docker [ansadmin@Y21ACS570-ansiblehost opt]$ ls -l
total 0
drwxr-xr-x. 4 root root 33 Nov 22 05:03 aws
drwxr-xr-x. 2 root root 6 Dec 15 23:50 docker
6
7
4/4 B. Tech CSE Y21ACS570 DevOps Lab

[ansadmin@Y21ACS570-ansiblehost opt]$ sudo chown -R


ansadmin:ansadmin docker
[ansadmin@Y21ACS570-ansiblehost opt]$ ls -l
total 0
drwxr-xr-x. 4 root root 33 Nov 22 05:03 aws
drwxr-xr-x. 2 ansadmin ansadmin 6 Dec 15 23:50
docker [ansadmin@Y21ACS570-ansiblehost opt]$ cd
docker [ansadmin@Y21ACS570-ansiblehost docker]$
nano Dockerfile

[ansadmin@Y21ACS570-ansiblehost docker]$ sudo nano /etc/ansible/hosts

[ansadmin@Y21ACS570-ansiblehost ~]$ ssh-copy-id 172.31.10.2


/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed:
"/home/ansadmin/.ssh/id_rsa.pub"
The authenticity of host '172.31.10.2 (172.31.10.2)' can't be
established. ED25519 key fingerprint is
SHA256:r8ejSAw3DuFGwdUE/SxZWsBdzTNcBXCkvvfhX8WZJSg.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])?
yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s),
to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you
are prompted now it is to install the new keys
[email protected]'s password:

Number of key(s) added: 1

Now try logging into the machine, with: "ssh '172.31.10.2'"


and check to make sure that only the key(s) you wanted were added.

6
8
4/4 B. Tech CSE Y21ACS570 DevOps Lab

[ansadmin@Y21ACS570-ansiblehost ~]$ ansible all -a uptime


[WARNING]: Platform linux on host 172.31.10.2 is using the
discovered Python interpreter at /usr/bin/python3.9, but future
installation of another Python interpreter could change the
meaning of that path. See https://docs.ansible.com/ansible-
core/2.15/reference_appendices/interpreter_discovery.html for
more information.
172.31.10.2 | CHANGED | rc=0 >>
23:53:24 up 19 min, 4 users, load average: 0.00, 0.02, 0.02
[WARNING]: Platform linux on host 172.31.2.115 is using the
discovered Python interpreter at /usr/bin/python3.9, but future
installation of another Python interpreter could change the
meaning of that path. See https://docs.ansible.com/ansible-
core/2.15/reference_appendices/interpreter_discovery.html for
more information.
172.31.2.115 | CHANGED | rc=0 >>
23:53:24 up 1:06, 3 users, load average: 0.08, 0.02, 0.01
[ansadmin@Y21ACS570-ansiblehost ~]$ ansible all -m ping
[WARNING]: Platform linux on host 172.31.2.115 is using the
discovered Python interpreter at /usr/bin/python3.9, but future
installation of another Python interpreter could change the
meaning of that path. See https://docs.ansible.com/ansible-
core/2.15/reference_appendices/interpreter_discovery.html for
more information.
172.31.2.115 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3.9"
},
"changed":
false, "ping":
"pong"
}
[WARNING]: Platform linux on host 172.31.10.2 is using the
discovered Python interpreter at /usr/bin/python3.9, but future
installation of another Python interpreter could change the
meaning of that path. See https://docs.ansible.com/ansible-
core/2.15/reference_appendices/interpreter_discovery.html for
more information.
172.31.10.2 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3.9"
},
"changed":
false, "ping":
"pong"
}
[ansadmin@Y21ACS570-ansiblehost ~]$ cd /opt/docker
[ansadmin@Y21ACS570-ansiblehost docker]$ nano
hello.yml

6
9
4/4 B. Tech CSE Y21ACS570 DevOps Lab

[ansadmin@Y21ACS570-ansiblehost docker]$ nano deploy_hello.yml

[ansadmin@Y21ACS570-ansiblehost docker]$ ansible-playbook


hello.yml -- syntax -check

playbook: hello.yml
[ansadmin@Y21ACS570-ansiblehost docker]$ ansible-playbook
deploy_hello.yml
--syntax -check

playbook: deploy_hello.yml

a. Open the Chrome browser, sign up for DockerHub, and once you have successfullysigned in,
create a repository manually as follows:

7
0
4/4 B. Tech CSE Y21ACS570 DevOps Lab

b. Click on create repository and provide name

[ansadmin@Y21ACS570-ansiblehost docker]$ docker login


Log in with your Docker ID or email address to push and pull images
from Docker Hub. If you don't have a Docker ID, head over to
https://hub.docker.com/ to create one.
You can log in with your password or a Personal Access Token (PAT).
Using a limited-scope PAT grants better security and is required
for organizations using SSO. Learn more at
https://docs.docker.com/go/access- tokens/

Username:
jaswanth440
Password:
WARNING! Your password will be stored unencrypted in
/home/ansadmin/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#creden
tials- store

Login Succeeded
[ansadmin@Y21ACS570-ansiblehost docker]$ sudo service docker start
[sudo] password for ansadmin:
Redirecting to /bin/systemctl start docker.service

In docker instance:
[root@Y21ACS570-dockerhost ec2-user]# sudo su - ansadmin
Last login: Sun Dec 15 23:53:34 UTC 2024 from 172.31.10.2 on pts/2
[ansadmin@Y21ACS570-dockerhost ~]$ docker login

7
1
4/4 B. Tech CSE Y21ACS570 DevOps Lab

Log in with your Docker ID or email address to push and pull images
from Docker Hub. If you don't have a Docker ID, head over to
https://hub.docker.com/ to create one.
You can log in with your password or a Personal Access Token (PAT).
Using a limited-scope PAT grants better security and is required
for organizations using SSO. Learn more at
https://docs.docker.com/go/access- tokens/

Username:
jaswanth440
Password:
WARNING! Your password will be stored unencrypted in
/home/ansadmin/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#creden
tials- store

Login Succeeded
[ansadmin@Y21ACS570-dockerhost ~]$ sudo chmod 777 /var/run/docker.sock

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

#1) Respect the privacy of


others. #2) Think before you
type.
#3) With great power comes great responsibility.

For security reasons, the password you type will not be

visible. [sudo] password for ansadmin:


[ansadmin@Y21ACS570-dockerhost ~]$
logout
[root@Y21ACS570-dockerhost ec2-user]# service docker start
Redirecting to /bin/systemctl start docker.service

In jenkins instance:
[ec2-user@Y21ACS570-Jenkins ~]$ sudo su
[root@Y21ACS570-Jenkins ec2-user]# service jenkins start
Redirecting to /bin/systemctl start jenkins.service

a. Open jenkins -> Goto Dashboard -> Manage Jenkins -> System -> SSH serversClick on Add
Provide the following as follows
Name: ansiblehost
Hostname: private ip of ansibleinstance
Username: ansadmin

7
2
4/4 B. Tech CSE Y21ACS570 DevOps Lab

b. expand the Advanced section and enable the checkbox provide, the password of
ansadmin which is present in ansible instance

7
3
4/4 B. Tech CSE Y21ACS570 DevOps Lab

c. Test the configuration. Make sure that the result obtained should be success. If the result is
success, then click on apply and then click on save

d. Create a new item from the existing item. provide the name for an item. Give the name
of existing item in copy from textbox

7
4
4/4 B. Tech CSE Y21ACS570 DevOps Lab

e. Install publish over SSH plugin if it is not installed, during the configuration of an item, In
SSH server give the following Name: ansiblehost

f. In Transfer Set give the following


Source files: target/*.war
Remove profile: target
Remote directory: //opt//docker
Exec command:
cd /opt/docker
ansible-playbook hello.yml
sleep 10 ansible-playbook
deploy_hello.yml

7
5
4/4 B. Tech CSE Y21ACS570 DevOps Lab

g. Click on apply and save. Click on Build Now and check the console output

Check the Docker Hub

Check in both instances to verify whether the image and the container have been created or not
In ansible instance:
[ansadmin@Y21ACS570-ansiblehost docker]$ sudo docker images
[sudo] password for ansadmin:
REPOSITORY TAG IMAGE ID CREATED SIZE
hello latest 57382b95e117 4 ago 472M
minutes B
jaswanth440/hello latest 57382b95e117 4 ago 472MB
minutes
jaswanth440/hello <none> afd61e499486 11 minutes ago 472MB
jaswanth440/hello <none> d33380e564a3 20 minutes ago 472MB

7
6
4/4 B. Tech CSE Y21ACS570 DevOps Lab

In docker instance:
[ansadmin@Y21ACS570-dockerhost docker]$ docker ps -a
CONTAINER ID IMAGE COMMAND
CREATED STATUS
PORTS NAMES
7125f5a87280 jaswanth440/hello:latest "catalina.sh run" 3
minutes ago Up 3 minutes 0.0.0.0:8087->8080/tcp, :::8087-
>8080/tcp hello- server
09552dd8c1d8 6c323c5b143b "catalina.sh run" 2 hours
ago Up 2 hours
0.0.0.0:8085->8080/tcp, :::8085->8080/tcp xtomcat-
container
130c6271b442 mtomcat "catalina.sh run" 2 hours
ago Up 2 hours
0.0.0.0:8082->8080/tcp, :::8082->8080/tcp mtomcat-
container
f0cfdcc3d9f9 tomcat "catalina.sh run" 2 hours
ago Up 2 hours
0.0.0.0:8081->8080/tcp, :::8081->8080/tcp tomcat-
container

7
7

You might also like