Would like to integrate/run ansible playbook via Jenkins

Hey, We’re looking integrating Ansible playbook via Jenkins. We’re running into challenges with setting up public/private keys for authentication.

What kinds of challenges are you running into?

We’re looking for steps/documentation on how to do this.

So, here is how I’ve managed it for myself:

Add the SSH keys to Jenkins Credentials and call them from the pipeline. You do need the ansible plugin to use this pipeline.

pipeline {
    agent { label 'aws' }
    environment {
        SSHKEY = credentials('jenkins-ansible')
        ANSIBLE_HOST_KEY_CHECKING = 'False'
        ANSIBLE_SCP_IF_SSH = 'True'
    }
    stages {
        stage('dev') {
            steps {
                ansiblePlaybook colorized: true, credentialsId: 'jenkins-ansible-key', disableHostKeyChecking: true, installation: 'ansible-2.6.3', inventory: 'inventory/development.yaml', playbook: 'updates.yaml'
            }
        }
        stage('prod') {
            when { branch 'master' }
            steps {
                ansiblePlaybook colorized: true, credentialsId: 'jenkins-ansible-key', disableHostKeyChecking: true, installation: 'ansible-2.6.3', inventory: 'inventory/production.yaml', playbook: 'updates.yaml'
            }
        }
    }
    post {
        always {
            sendNotifications(currentBuild.currentResult)
        }
    }
}

Hmm, I don’t remember why I have two keys listed or settings both in environment and the ansible step. Do experiment with those to see which ones you truly need.

We will be using ansible user to login remote node, via ssh, so within jenkins should we provide private key of ansible user? That’s the part we’re trying to figure out.
Then there is github repository when we will keep the playbook. how do we pass that credential.