Skip to content

Jenkins pipeline for deploying java-webapp using ansible playbook.

Notifications You must be signed in to change notification settings

mahendra-shinde/jenkins-ansible-javaapp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Setup Jenkins with Ansible for deployment

  1. Start Jenkins server, connect using SSH inside Jenkins Master.
$ sudo apt update -y
$ sudo apt install ansible -y
  1. Visit Jenkins Dashboard, Install new plugin "Ansible Plugin" Use "Install without Restart"

  2. From Jenkins dashboard, goto "Global Tool Configuration" > Setup path for Ansible "/usr/bin"

  3. Create an additional virtual machine in same VPC / VNet as jenkins master. Lets call it "Sample1"

  4. Use SSH connection with Jenkins Master, to create a new SSH Keypair and Use "private-key" in Jenkins credentials and public-key tobe copied to "Sample1"

## Become JENKINS user
$ sudo -i
$ su - jenkins
$ mkdir temp
$ ssh-keygen 
Path for Public Key: $PWD/temp/id_rsa.pub
Pass Phrase: <ENTER>
$ cd temp
$ ls
## Lets copy PUBLIC Key to Sample1
## Private IP of Sample1 : 10.0.1.5
$ ssh-copy-id -i $PWD/temp/id_rsa.pub [email protected]
Accept the server thumbprint: YES
## Change File permissions of SSH Keys
$ chmod 600 id_rsa
$ chmod 600 id_rsa.pub
## Test the connectivity with 10.0.1.5
$ ssh -i $PWD/temp/id_rsa [email protected]
## You should be now connected
$ exit
## Display contents of PRIVATE KEY on Screen
$ cat id_rsa
## Just COPY entire private key
  1. Open Jenkin dashboard > Manage Credentials > Global Credential Manager "Jenkins" > Add Credentials

    Choose option "SSH Username with private key"

    ID: webhostid
    Description: SSH Credentials for Web Host
    Username: mahendra
    Private Key: Enter Directly
        PASTE the key copied from SSH Terminal

    Save the credentials

  2. Login in GitHub and FORK this repository 'https://github.com/mahendra-shinde/jenkins-ansible-javaapp'

  3. From inside the remote server, get private ip address (Use AWS Console or Azure Portal)

    $ hostname -i
    
  4. Get inside the FORKED repository (create in step#7) and edit file 'deployment/evniornment.ini'

    Replace these line:

    [webhosts]
    10.0.1.5 ansible_user=mahendra

    With these [Please replace 172.17.9.2 with Private IP of Your VM, and 'azureuser' with Username of VM ]:

    [webhosts]
    172.17.9.2 ansible_user=azureuser
  5. After making changes, just use "Commit " button.

  6. Modify the Jenkinsfile inside your repository and Update line #11. You need to replace repository URL. Then use "Commit" button.

  7. Login in Jenkins Dashboard, and create a new "Pipeline Project"

    Description: Ansible integration demo
    Pipeline:   
            Pipeline from SCM
            SCM: Git
            Repository URL: YOUR-REPO-URL
  8. Save the Job, and use "Build Now"

  9. Verify the build console and once build is SUCCESS, use PUBLIC-IP of Target VM.

    http://PUBLIC-IP:8080/

About

Jenkins pipeline for deploying java-webapp using ansible playbook.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages