Jenkins and Ansible Playbook - Part 1

By Rajib Bahar at May 28, 2022 12:42
Filed Under: Data, DevOps

This is a sample Jenkins file I have used in past projects with Ansible & Docker technologies. In part 1, I'll share what the Jenkins template looks like. In the next part, I'll share the actual playbooks. 

 

 

pipeline {
    agent any

    stages {
        stage('Ansible Playbook to clone code...') {
            steps {
                echo 'Clone repo'
                ansiblePlaybook installation: 'Ansible', playbook: '/project/ansible_project/0_clone_repo.yaml'
            }

            post { 
                success { 
                    echo 'Done with cloning...'
                }
            }
        }
        stage('Ansible Playbook to build code...') {
            steps {
                echo 'Build code using maven...' 
                ansiblePlaybook installation: 'Ansible', playbook: '/project/ansible_project/1_build_repo.yaml'
            }

            post { 
                success { 
                    echo 'Done with building...'
                }
            }
        }
        stage('Ansible Playbook to deploy production configuration & cleanup...') {
            steps {
                echo 'Deploy production artifacts...' 
                ansiblePlaybook installation: 'Ansible', playbook: '/project/ansible_project/2_deploy.yaml'
            }

            post { 
                success { 
                    echo 'Done with deploying...'
                }
            }
        } 
    }
}

    

Tag cloud

Month List