Top Banner
Testing Ansible with Jenkins and Docker Dennis Rowe @shr3kst3r wpengine.com
38
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Testing Ansible with Jenkins and Docker

Testing Ansible with Jenkins and Docker

Dennis Rowe@shr3kst3r

wpengine.com

Page 2: Testing Ansible with Jenkins and Docker

Goals

Verify the Ansible codeRun the Ansible code

Verify the Results

Page 3: Testing Ansible with Jenkins and Docker

• Why we are here

• Automation

• Configuration Management

Page 4: Testing Ansible with Jenkins and Docker

• “An extensible open source continuous integration server”

• Lets us run stuff

• Plugins lets you do extra stuff

Page 5: Testing Ansible with Jenkins and Docker

• The new hotness

• Containers

• Tools for containers

Page 6: Testing Ansible with Jenkins and Docker

Note

• So, I did it two ways.

• First way, meh

• Second way, less meh, more weeee

Page 7: Testing Ansible with Jenkins and Docker

The First Way

Page 8: Testing Ansible with Jenkins and Docker

We Need Two Jobs

Page 9: Testing Ansible with Jenkins and Docker

Building a Docker Image

Page 10: Testing Ansible with Jenkins and Docker

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)

Page 11: Testing Ansible with Jenkins and Docker

Add “Execute shell” Build Step

Page 12: Testing Ansible with Jenkins and Docker

Dockerfile

Page 13: Testing Ansible with Jenkins and Docker

Running the Build

Page 14: Testing Ansible with Jenkins and Docker

Docker Images

Page 15: Testing Ansible with Jenkins and Docker

Running Test with Docker

Page 16: Testing Ansible with Jenkins and 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

Page 17: Testing Ansible with Jenkins and Docker

Docker plugin (configure system)

Page 18: Testing Ansible with Jenkins and Docker

Add a SSH Remote

Page 19: Testing Ansible with Jenkins and Docker

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)

Page 20: Testing Ansible with Jenkins and Docker

Start Container

Page 21: Testing Ansible with Jenkins and Docker

Execute Tests

Page 22: Testing Ansible with Jenkins and Docker

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

Page 23: Testing Ansible with Jenkins and Docker

Stop Dockers

Page 24: Testing Ansible with Jenkins and Docker

Build

Page 25: Testing Ansible with Jenkins and Docker
Page 26: Testing Ansible with Jenkins and Docker
Page 27: Testing Ansible with Jenkins and Docker

Test Container

• I can actually get access to the running container

• Just delete the “Post-build Action”

• Then run the build

Page 28: Testing Ansible with Jenkins and Docker

Left Over Container

Page 29: Testing Ansible with Jenkins and Docker

ssh

Page 30: Testing Ansible with Jenkins and Docker

The Second Way

Page 31: Testing Ansible with Jenkins and Docker

Notes

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

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

Page 32: Testing Ansible with Jenkins and Docker

Thats All

Page 33: Testing Ansible with Jenkins and Docker

Bonus

Page 34: Testing Ansible with Jenkins and Docker

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

Page 35: Testing Ansible with Jenkins and Docker
Page 36: Testing Ansible with Jenkins and Docker

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

Page 37: Testing Ansible with Jenkins and Docker

Ansible and Docker

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

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

Page 38: Testing Ansible with Jenkins and Docker

Odds and Ends

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

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