Project Solution 1
Project Solution 1
Subject: - configure and manage slave node using automated build pipeline
Subject - Deployment of the project is PHP application we will handling Test Server
machine to completely from the Master.
Configuring Test Server with Master and deployment to Test Server machine.
Overview: -
Task: -
Install Java, Jenkins, Ansible on the machine. And add that Test Server Machine Ansible
Hosts.
Also add Jenkins in our Test Server.
Then we will deploy our application using the ansible first configure Test Server
machine.
Install all the dependencies Java, chromium browsers, chrome driver etc. on the Test
Server.
Using Jenkins, we have to deploy our PHP applications. We will dockerize first and then
we will deploy it.
Now 1st we will download the ansible playbook and download the all thing in master
instances.
(Jenkins, Java, Ansible in the master)
The thing is very important because we are using instance type t2. micro. there is some
limitation t2. micro 1 GB of RAM per instance. Limitation of 1 GB RAM is that you
can’t install the Jenkins and puppet in same machine.
Since, puppet and Ansible we are using for same thing like configuration management.
So, we don’t require both of them.
We are using only ansible here for our project.
Now, Master machine we will install Git, Java, Jenkins.
Let’s connect to master and install the all these.
3. We will set project.pem key pair, so firstly we will create the .ppk file for connect to master.
4. Now selects the project.ppk file in SSH authentications.
5. Now EC 2 instance Master has been connected through putty.
Add the Jenkins software repository to the source list and provide the authentication key:
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian- stable binary/ | sudo tee
/etc/apt/sources.list.d/jenkins.list > /dev/null
13. For Open Jenkins in browser: - we have used public IP of Master EC 2 instances.
14. Use public IP in browser.
15. Jenkins Run as port 8080
16. Add the password
17. Add Password and continue.
From our control node, run the following command to include the official project’s PPA
(personal package archive) in your system’s list of sources:
22. Next, refresh your system’s package index so that it is aware of the packages available in
the newly included PPA:
23. Following this update, we can install the Ansible software with:
sudo apt install ansible
24. Our Ansible control node now has all of the software required to administer hosts. Next,
we will go over how to add our hosts to the control node’s inventory file so that it can
control them.
25. After installation of Ansible in Master machine. Then we will install the ansible in Slave
machine (Test Server).
Now we will connect the Test Server instance EC2 via Putty.
Test Server Public IP: -
Key pair: - Projects
Slave Test server EC2 instance.
1. First thing does update the packaging.
Command: cd .ssh/
Command: ls
7. While making the SSH connection they checking the Key. Key is valid or key is
matching then connection would be established.
Command: - Cat .ssh/id_rsa.pub
Open the public key and copy the key.
8. Now go to the slave , SSH directory
9. Copy the public key master machine in the slave machine of authorized file.
10. Command: - sudo nano authorized_keys in slave machine
11. Open the command line.
12. Paste master machine public in second line.
19. Now we have edited the Test Server machine inventory file of ansible.
20. We try to ping that machine which the ansible reach that machine or not.
21. To do that, command ansible -m ping groupname.
Command: - ansible -m ping webserver
22. We able to ping the second machine using ansible command. Once ansible connection is
establish.
23. Now, in master machine we have to installed git, Java, Jenkins, Ansible.
24. Now, Ansible we have to configure in Test Server machine. We have installing require
tools like git, java , docker, chrome driver, chromium browser on to the Test server
machine.
25. For install the chrome driver - firstly the chrome driver installs to the master machine.
26. Then directly copy the chrome driver Master to Test Server.
27. Run the command directly using ansible to Test Server machine. There are 5-6
command. It will increase the playbook size. Rather we do first install the chrome driver
on to the master and then directly copy to the Test server machine using ansible
playbook.
28. For chrome driver installation command is below: -
sudo apt-get update
sudo apt-get install -y unzip xvfb libxi6 libgconf-2-4
sudo curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add
sudo echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >>
/etc/apt/sources.list.d/google-chrome.list
30. Now, directly copy the chromedriver to our test server machine.
31. Write the ansible playbook to install the dependencies of the Test Server machine.
32. Creating first playbook now,
33. Any playbook name (command: - sudo nano project.yml)
34. Write the playbook.
---
- hosts: all
become: true
tasks:
package:
name: git
state: present
apt:
update_cache: true
package:
name: openjdk-11-jdk
state: present
apt:
update_cache: yes
Script: -
---
- hosts: all
become: yes
become_user: root
tasks:
- name: Add Docker GPG key
apt_key: url=https://download.docker.com/linux/ubuntu/gpg
1. Open Jenkins.
2. Username: Nikhil
3. Password:
4. Click on manage Jenkins.
23. Now, copy java.jar command we have run this command on slave/ Test server machine
to establish the connection
24. First open new terminal and connect to slave machine.
25. Now copy the java.jar command from jenkins to Master machine
FROM devopsedu/webapp
RUN rm /var/www/html/index.html
47. source code management - select Git and add the Repository URL.
48. Then Build, add build step select Execute shell.
49. We have run shell command to build the docker file and then to run docker image
which will be created.
50. Click and type -
sudo docker build -t phpapplication .
sudo docker run -itd -p 8081:80 phpapplication
51. Then apply and save