Skip to content

Ansible

Ansible deployments

Ansible

Deployments

There are two recommended methods for creating ansible deployments. 1. Fully Inclusive Playbook 2. Deployment Repository

Deployment Requirements

  1. SSH Keys configured
  2. The SSH keys are extremely important in an ansible deployment.
  3. Ansible Host Server
  4. Having a server with Ansible installed is key for deploying. This can either be a slave server spun up on the CI tool, or a container with ansible pre-configured on it.
  5. Python installed on inventory servers
  6. One common problem is the servers have the wrong versions of python installed. Having python updates as part of the ansible checks before execution is useful.

Fully Inclusive Playbook

This is a repository that includes playbooks, configurations, roles, and Jenkinsfile

Example Jenkins Pipeline

pipeline{
    stages{
        stage('RND') {
            sh 'ansible-playbook -i inventory.yml rnd --key_file=KEYFILE'
        }
        stage('QA')  {
            sh 'ansible-playbook -i inventory.yml qa --key_file=KEYFILE'
        }
    }

}

Deployment Repository

This is a repository that includes only playbooks and configuration files. The roles are imported on demand either using git clones or importing artifacts.

pipeline{
    stages{
        stage('RND') {
            dir('roles/NAME-OF-ROLE') {
                //Clone external repository
                //Download and unzip ansible role artifact
            }
            sh 'ansible-playbook -i inventory.yml rnd --key_file=KEYFILE'
        }
        stage('QA')  {
            dir('roles/NAME-OF-ROLE') {
                //Clone external repository
                //Download and unzip ansible role artifact
            }
            sh 'ansible-playbook -i inventory.yml qa --key_file=KEYFILE'
        }
    }

}