- Developer write a code and push the code in github. Github is integrate with Jenkins. Jenkins job run compiling & building. after compiling jenkins its created a file and jenkins pushed this file in Ansible. Jenkis triggered a playbook written in Ansible. In this playbook I write a code for deploy a software on Web-server. so, Developer do any changes in code it directly change in web-server.
https://medium.com/@rutikdevops/complete-devops-cicd-project-18faf4b5f73d
- Create 4 ec2 instance name as:- (AWS Linux-2, t2 micro)
- Jenkins-Server
- Ansible-Server
- Web-Server
- Developer
ec2-user
sudo su
yum update -y
hostnamectl set-hostname jenkins
bash- Java installation on Jenkins server:-
yum install java* -y
java --version
alternatives --config java ## Using this command you can choose any version of Java- Jenkins installation on Jenkins server:-
wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
yum install jenkins -y
systemctl enable jenkins.service
systemctl start jenkins.service
systemctl status jenkins.service- set root passwd
passwd root - Now, enter passwd 2 times
vim /etc/ssh/sshd_config- Do this changes in vi editor:- ** #PermitRootLogin yes (remove #) ** PasswordAuthentication no (replace no to yes) Now run this command:-
systemctl restart sshd- git installation on Jenkins server:-
yum install git -y- Copy public ip of jenkins server and paste it in new tab with port no.8080
- copy this path and paste in terminal with "cat" command
cat /var/lib/jenkins/secrets/initialAdminPassword- Now copy & paste this passwd in jenkins. so, jenkins is ready.
ec2-user
sudo su
yum update -y
hostnamectl set-hostname Ansible
bash- Ansible installation on Ansible server:-
yum install ansible -y
amazon-linux-extras install ansible2 -y
ansible --version- Now go to inventory file and add entry of web server
vim /etc/ansible/hosts- In that inventory file you can simply add
[web]
(paste here web-servers private ip)ec2-user
sudo su
yum update -y
hostnamectl set-hostname web-server
bash- httpd Apache installation on web-server:-
yum install httpd -y
systemctl enable httpd
systemctl start httpd- Go to ansible server and type command
ssh-keygen ##(and press enter 2 to 3 times)ssh-copy-id -i root@(paste web-server private ip here)- Go to web-server and type command
passwd root ##(Now enter passwd 2 times)vim /etc/ssh/sshd_config- Do this changes in vi editor:- ** #PermitRootLogin yes (remove #) ** PasswordAuthentication no (replace no to yes)
- Now run this command:-
systemctl restart sshd- Go to ansible server and type command
ssh-copy-id -i root@(paste web-server private ip here)enter passwd
root@(paste web-server private ip here)exit ##for go to web-server to ansible- Now, your Passwordless connection between Ansible & Web server is successfull
- Follow same steps from point no. 4 for jenkins to ansible connection
- create a directory in ansible
mkdir /sourcecode- Go to sourcecode directory
cd /sourcecode- Now, create a playbook name as,
playbook.yml- In playbook.yml file type,
- hosts: all
tasks:
- copy:
src: /opt/index.html
dest: /var/www/html- Github>> Create repo>> DevOps-Project-1(repo name)
- Create new file>>index.html(file name)
- In this file write,
My Name is Rutik- Github>> Settings>> Webhooks
- Payload URL:- (paste jenkins URL here)
- content type:- Application/json
- Secret:- Go to jenkins>>configure>>API Token>>add token>>copy token>>apply>>save ===> Paste this token
- Add Webhook>>click on page refresh
- Manage_jenkins>> Plugins>> available plugin>> publish over SSH>> restart jenkins
-
New_Item>> Project-1(Item_name)>> Freestyle_Project
-
Source code mangmt>> copy code URL from github
-
Project-1>>configure>>build>>Send files or execute commands over SSH

-
Exec command:-
rsync -avh /var/lib/jenkins/workspace/project-1/*.html root@(paste ansible private ip here):/opt/index.htmlansible-playbook /sourcecode/playbook.yml- copy public ip of web-server and paste it in new tab
- connect developer server with putty
yum install git -ygit clone https://github.com/rutikdevops/DevOps-Project-1.gitcd DevOps-Project-1vim index.htmlDo some changes in vi editor
My name is Rutik welcome to devops projectgit commit -m "f1" index.htmlgit push origin master
- Technical Cloud Knowledge - YouTube https://youtu.be/YsVJd0FPoYQ



