ansible with jenkins pipeline

24 views
Skip to first unread message

Sidh

unread,
Feb 14, 2018, 11:25:49 AM2/14/18
to Ansible Project
Hi,

Anyone using ansible with jenkins pipeline ?

Can you please point me to some documentation with examples ?

Regards,
Sidh

Michael Bubb

unread,
Feb 15, 2018, 1:17:41 PM2/15/18
to Ansible Project
Are you familiar with groovy syntax? To play around you can setup a pipeline job and create stages for the steps that you want the job to handle.

here is an example stage where yu call a playbook with parameters

stage('deploy') {
 
if ("${DEPLOY_FLAG}" == "true") {
   
// def SSH_KEY='<path>/deploy_id_rsa'
   
def DEP_PLAYBOOK='<path>/deploy_app.yml'
    sh
"ansible-playbook --private-key=${SSH_KEY} -b -e MY_WORKSPACE=${workspace}  ${DEP_PLAYBOOK} -l ${DEPLOY_TARGET}"
 
}
}


it works nicely and you can see the status of the stages on the job home page.

So an example job which builds and deploys might have stages where you 

- pull from source mgmnt
- verify
- build
- build test
- deploy to canary
- sanity check
- deploy
- deploy verification
- tests ...
- post deploy notification

All in one script -

Note in my example the conditional - you can set that either in the gui or in github post hooks etc. So the same pipeline file can handle build tests as well as deploys, etc

I would dive in and sandbox until yuo get comfortable
Reply all
Reply to author
Forward
0 new messages