Skip to content

rutikdevops/DevOps-Project-1

Repository files navigation

Complete DevOps CICD Project

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

Developer (1)

Detailed Blog Link:

https://medium.com/@rutikdevops/complete-devops-cicd-project-18faf4b5f73d

Project Steps :

  • Create 4 ec2 instance name as:- (AWS Linux-2, t2 micro)
  1. Jenkins-Server
  2. Ansible-Server
  3. Web-Server
  4. Developer
image

1. Connect Jenkins server with putty :-

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
image
  • 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.



2. Connect Ansible server with putty :-

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)



3. Connect web server with putty :-

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



4. Passwordless connection between Ansible & Web server :-

  • 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



5. Passwordless connection between Jenkins to Ansible server :-

  • Follow same steps from point no. 4 for jenkins to ansible connection



6. Create a Playbook in ansible server:-

  • 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



7. Create a Github repo:-

  • Github>> Create repo>> DevOps-Project-1(repo name)
  • Create new file>>index.html(file name)
  • In this file write,
My Name is Rutik



8. Integrate Github with Jenkins:-

  • 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



9. Install plugin in jenkins:-

  • Manage_jenkins>> Plugins>> available plugin>> publish over SSH>> restart jenkins



10. Create project in Jenkins:-

  • New_Item>> Project-1(Item_name)>> Freestyle_Project

  • Source code mangmt>> copy code URL from github

  • Manage_jenkins>> Configure_system image

  • Project-1>>configure>>build>>Send files or execute commands over SSH image

  • Exec command:-

rsync -avh /var/lib/jenkins/workspace/project-1/*.html root@(paste ansible private ip here):/opt/index.html
  • Manage_jenkins>> Configure_system image

  • Project-1>>configure>>Post-build Actions>>Send build artifacts over SSH image

  • Exec command:-

ansible-playbook /sourcecode/playbook.yml



11. Host website on web-server:-

  • copy public ip of web-server and paste it in new tab



12. Access Developer system:-

  • connect developer server with putty
yum install git -y
git clone https://github.com/rutikdevops/DevOps-Project-1.git
cd DevOps-Project-1
vim index.html

Do some changes in vi editor

My name is Rutik welcome to devops project
git commit -m "f1" index.html
git push origin master



13. Output:-

image

Project Reference :-

About

Jenkins, Maven, Docker

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages