testing ansible with jenkins and docker

38
Testing Ansible with Jenkins and Docker Dennis Rowe @shr3kst3r wpengine.com

Upload: dennis

Post on 15-Jul-2015

1.243 views

Category:

Technology


6 download

TRANSCRIPT

Testing Ansible with Jenkins and Docker

Dennis Rowe@shr3kst3r

wpengine.com

Goals

Verify the Ansible codeRun the Ansible code

Verify the Results

• Why we are here

• Automation

• Configuration Management

• “An extensible open source continuous integration server”

• Lets us run stuff

• Plugins lets you do extra stuff

• The new hotness

• Containers

• Tools for containers

Note

• So, I did it two ways.

• First way, meh

• Second way, less meh, more weeee

The First Way

We Need Two Jobs

Building a Docker Image

Create our First Jenkins Project

• Create a freestyle project called “Build Docker Image”

• Use custom workspace (under Advanced). I set my workspace to build_docker_image.

• Configure the source repository (https://github.com/shr3kst3r/ansible-jenkins-example.git)

Add “Execute shell” Build Step

Dockerfile

Running the Build

Docker Images

Running Test with Docker

Docker Plugins

• “Docker plugin”

• https://wiki.jenkins-ci.org/display/JENKINS/Docker+Plugin

• “SSH plugin”

• https://wiki.jenkins-ci.org/display/JENKINS/SSH+plugin

Docker plugin (configure system)

Add a SSH Remote

Create our Second Jenkins Project

• Create a freestyle project called “Project Test Ansible with Docker”

• Use custom workspace (under Advanced). I set my workspace to docker_ansible.

• Configure the source repository (https://github.com/shr3kst3r/ansible-jenkins-example.git)

Start Container

Execute Tests

test_it• Lint Ansible code using ansible-lint

(https://github.com/willthames/ansible-lint)

• Run the Ansible playbook

• Verify environment using Serverspec (http://serverspec.org/)

• Source: https://github.com/shr3kst3r/ansible-jenkins-example/blob/master/test_it

Stop Dockers

Build

Test Container

• I can actually get access to the running container

• Just delete the “Post-build Action”

• Then run the build

Left Over Container

ssh

The Second Way

Notes

• Similar two the first way, but no Jenkins plugins.

• Derived from the book “The Docker Book” by James Turnbull

Thats All

Bonus

Testing on my Mac

• http://boot2docker.io/

• docker build -t jenkins-ansible .

• docker run -v "/Users/dennis/git/ansible-jenkins-example:/build:rw" jenkins-ansible /bin/bash -c 'cd /build && ./test_it’

• docker rm $(docker ps -a -q) # delete

Benefits

• Super fast start times. Do not have to spin up a server.

• Allows for a very quick test lifecycle (22 seconds total time for this simple example)

• Reproducible and Consistent

Ansible and Docker

• Some General Info (interesting video): http://www.ansible.com/docker

• Docker Module: http://docs.ansible.com/docker_module.html

Odds and Ends

• https://github.com/shr3kst3r/ansible-jenkins-example

• You can reach me at [email protected] or @shr3kst3r on the twitters