# Running Ansible playbook with Jenkins plugin ... now need to add git

**URL:** <https://forum.ansible.com/t/running-ansible-playbook-with-jenkins-plugin-now-need-to-add-git/32837>\
**Category:** Ansible Project\
**Created:** [May 3, 2020, 2:59am UTC](https://forum.ansible.com/t/running-ansible-playbook-with-jenkins-plugin-now-need-to-add-git/32837 "2020-05-03T02:59:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kiran\_Kumar](https://avatars.discourse-cdn.com/v4/letter/k/f475e1/32.png) [@Kiran\_Kumar](https://forum.ansible.com/u/Kiran_Kumar)\
**Post date:** [May 3, 2020, 2:59am UTC](https://forum.ansible.com/t/running-ansible-playbook-with-jenkins-plugin-now-need-to-add-git/32837/1 "2020-05-03T02:59:39Z")

</div>

Hi,

I have a ansible server, which i use mainly to manage ntp client/dns client/time zone/create users/install software etc on various linux servers… so no development to say, just as “infrastructure as code”

On same server i installed Jenkins & on Jenkins i installed ansible plugin. Now i have a UI ( Front end ) for my playbooks. So Jenkins runs the playbooks.

So far so good.

Now i am scratching my head & doing google ( and various online training ) how do i ensure all those playbook & roles etc to add to GIT & then manage with GIT.

This is what i did so far

- Install git plugin of Jenkins on same server
- Install git server on same server, now this server acts as Jenkins+Ansible + Git
- Test my git server by creating a project on it & testing with a work-station

All stuff on my ansible is under /etc/ansible ie playbook in /etc/ansible/playbooks , roles in /etc/ansible/roles , inventory at /etc/ansible/hosts

Please suggest ( any good blog/web page/book ) or otherwise any suggestions will help

Thanks  
Kiran

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [May 3, 2020, 6:48am UTC](https://forum.ansible.com/t/running-ansible-playbook-with-jenkins-plugin-now-need-to-add-git/32837/2 "2020-05-03T06:48:22Z")

</div>

This looks like a question about how to use git, in combination with Jenkins, neither of which this list is supporting. You might get more response from a support forum on Jenkins.

---

<div class="post-metadata">

**Author:** ![Vivek\_Kothawale](https://avatars.discourse-cdn.com/v4/letter/v/ea666f/32.png) [@Vivek\_Kothawale](https://forum.ansible.com/u/Vivek_Kothawale)\
**Post date:** [May 3, 2020, 6:56am UTC](https://forum.ansible.com/t/running-ansible-playbook-with-jenkins-plugin-now-need-to-add-git/32837/3 "2020-05-03T06:56:23Z")

</div>

Hi

To achieve the above mentioned objective you can wirte Jenkins file and package all the files using fpm and deploy that package in jenkins server and then you can run playbooks using ansible jenkins by providing path to playbook.

Thanks and Regards,  
Vivek

---

<div class="post-metadata">

**Author:** ![Kiran\_Kumar](https://avatars.discourse-cdn.com/v4/letter/k/f475e1/32.png) [@Kiran\_Kumar](https://forum.ansible.com/u/Kiran_Kumar)\
**Post date:** [May 6, 2020, 3:59am UTC](https://forum.ansible.com/t/running-ansible-playbook-with-jenkins-plugin-now-need-to-add-git/32837/4 "2020-05-06T03:59:20Z")

</div>

Thanks Vivek

---

<div class="post-metadata">

**Author:** ![Nicola\_L](https://avatars.discourse-cdn.com/v4/letter/n/9dc877/32.png) [@Nicola\_L](https://forum.ansible.com/u/Nicola_L)\
**Post date:** [May 6, 2020, 4:30pm UTC](https://forum.ansible.com/t/running-ansible-playbook-with-jenkins-plugin-now-need-to-add-git/32837/5 "2020-05-06T16:30:08Z")

</div>

Hi,  
first thing you should version all your playbooks and roles in a git repository.  
Then you tell Jenkins to pull such git repository and run the playbook you want to.

Be sure that on the Jenkins host you have installed all the required software: ansible, git.

You can create a Jenkinsfile at the root of your project that describes the steps that Jenkins has to perform in order to run your playbook:  
Example for my Jenkinsfile that does something on my aws instances:

pipeline {  
agent any

environment {  
AWS\_ID = credentials(“aws\_credentials”)  
AWS\_ACCESS\_KEY\_ID = “${env.AWS\_ID\_USR}”  
AWS\_SECRET\_ACCESS\_KEY = “${env.AWS\_ID\_PSW}”

ANSIBLE\_VAULT\_PASSWORD\_FILE = credentials(“ansible-vault-password-file”)

SSH\_PRIVATE\_KEY\_FILE = credentials(“ssh-private-key-file”)  
}

stages {  
stage(“prepare virtualenv”) {  
steps {  
withPythonEnv(‘python’) {  
sh “”"  
pip install -r ansible/pip/pip-requirements.txt  
“”"  
}  
}  
}

stage(“run playbook”) {  
steps {  
withPythonEnv(‘python’) {  
sh “”"  
cd ansible  
ansible-playbook my-playbook.yml --extra-vars “target=targethost” --private-key $SSH\_PRIVATE\_KEY\_FILE --vault-password-file $ANSIBLE\_VAULT\_PASSWORD\_FILE  
“”"  
}  
}  
}  
}  
}
