Example for building an artifact using Jenkins and deploying it using Ansible

+1 vote
Can you give an example for building an artifact using Jenkins and deploying it using Ansible? Can you describe the steps of achieving the same?
Jul 31, 2019 in Jenkins by Harsh
8,170 views

1 answer to this question.

+3 votes

Hey @Harsh, follow this to get an understanding on building an artifact using Jenkins and Deploying it using Ansible.  

Install "publish Over SSH" plugin

Manage Jenkins > Manage Plugins > Available > Publish over SSH

Enable connection between Ansible and Jenkins

Manage Jenkins > Configure System > Publish Over SSH > SSH Servers

SSH Servers:

Hostname:<ServerIP>
username: username
password: *******

Test the connection "Test Connection"

create a copywarfile.yml on Ansible under /opt/playbooks

# example.yml
---
- hosts: all 
  become: true
  tasks: 
    - name: example
        copy:
          src: /op/playbooks/wabapp/target/webapp.war
          dest: /opt/apache-tomcat-8.5.32/webapps

Add tomcat server details to /etc/ansible/hosts (if you are using other hosts file update server info there)

echo "<server_IP>" >> /etc/ansible/hosts

Create Jenkins job, Fill the following details,

Source Code Management:

Repository: https://github.com/path/hello-world.git
Branches to build : */master

Build:

Root POM:pom.xml
Goals and options : clean install package

Add post-build steps

Send files or execute commands over SSH
SSH Server : ansible_server
Source fiels: webapp/target/*.war
Remote directory: //opt//playbooks

Add post-build steps

Send files or execute commands over ssh
SSH Server : ansible_server
Exec command ansible-playbook /opt/playbooks/example.yml
Execute job and you should be able to seen build has been deployed on Tomcat server.

answered Aug 1, 2019 by Vijay
Actually Jenkins war files were avilable under /var/lib/jenkins/workspace/.... folder right

How you got the webapp/webapp.war file under /opt/playbook folder ..

Have you written any job for copying that or you did the manually. if you did manually what is use of automation here??

or if you did it automatically, tell me the steps ..

Thanks

VENKATESH

Hi @Venkash, I have used Ansible to automate everything here. Yes, I have used /opt/playbook as my remote working directory for Jenkins. So my war file got created here. But you can use ansible and automate the copying this file to whichever location you want.

Syntax:

    copy:
          src: Source/location
          dest: Destination/location
I am getting error while testing the connection

SSH Servers:

Hostname:<ServerIP>
username: username
password: *******

Test the connection "Test Connection"

I have following question:

1. for this example, is ansible server, tomcat and jenkins is downloaded on same server or ansible server is on different server?

2. where is this username and password ? do we have to create it in ansible and if, yes where ?
i) Ansible server, tomcat, and Jenkins are all downloaded on the same server.

ii) The username and password in the ssh server section is the username and the password of the host system into which you are trying to ssh. This has nothing to do with ansible. You can change the password if you have the system's root access.

Related Questions In Jenkins

0 votes
1 answer

Why is it displaying Jenkins build failure for Android app

I think you should try this. Try Uninstalling ...READ MORE

answered Apr 12, 2018 in Jenkins by shubham
• 7,340 points
1,806 views
0 votes
2 answers

Is possible for Jenkins to auto start and stop slave nodes?

Try Jenkins Plugin called as Slave SetupPlugin. This ...READ MORE

answered Aug 6, 2018 in Jenkins by Nilesh
• 7,060 points
6,887 views
0 votes
1 answer

Ansible or Jenkins pipelines for bigger jobs

Well, you are indeed well aware of ...READ MORE

answered Jun 17, 2018 in Jenkins by shubham
• 7,340 points
1,016 views
+1 vote
1 answer

Unable to access Jenkins. I newly installed Jenkins but for some reason I cannot access it.

Try changing the port, Change JENKINS_AJP_PORT="xyz" to JENKINS_AJP_PORT="abc" If changing the ...READ MORE

answered Jul 4, 2018 in Jenkins by Sophie may
• 10,620 points
8,346 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,062 views
+2 votes
1 answer
0 votes
2 answers
+1 vote
3 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP