Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Testing Ansible with Jenkins and Docker

16,160 views

Published on

My slides given for a talk about testing Ansible code with Jenkins and Docker.

Published in: Technology
  • nice! thx
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Testing Ansible with Jenkins and Docker

  1. 1. Testing Ansible with Jenkins and Docker Dennis Rowe @shr3kst3r wpengine.com
  2. 2. Goals Verify the Ansible code Run the Ansible code Verify the Results
  3. 3. • Why we are here • Automation • Configuration Management
  4. 4. • “An extensible open source continuous integration server” • Lets us run stuff • Plugins lets you do extra stuff
  5. 5. • The new hotness • Containers • Tools for containers
  6. 6. Note • So, I did it two ways. • First way, meh • Second way, less meh, more weeee
  7. 7. The First Way
  8. 8. We Need Two Jobs
  9. 9. Building a Docker Image
  10. 10. 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)
  11. 11. Add “Execute shell” Build Step
  12. 12. Dockerfile
  13. 13. Running the Build
  14. 14. Docker Images
  15. 15. Running Test with Docker
  16. 16. Docker Plugins • “Docker plugin” • https://wiki.jenkins-ci.org/display/ JENKINS/Docker+Plugin • “SSH plugin” • https://wiki.jenkins-ci.org/display/ JENKINS/SSH+plugin
  17. 17. Docker plugin (configure system)
  18. 18. Add a SSH Remote
  19. 19. 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)
  20. 20. Start Container
  21. 21. Execute Tests
  22. 22. 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
  23. 23. Stop Dockers
  24. 24. Build
  25. 25. Test Container • I can actually get access to the running container • Just delete the “Post-build Action” • Then run the build
  26. 26. Left Over Container
  27. 27. ssh
  28. 28. The Second Way
  29. 29. Notes • Similar two the first way, but no Jenkins plugins. • Derived from the book “The Docker Book” by James Turnbull
  30. 30. Thats All
  31. 31. Bonus
  32. 32. 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
  33. 33. 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
  34. 34. Ansible and Docker • Some General Info (interesting video): http://www.ansible.com/docker • Docker Module: http:// docs.ansible.com/docker_module.html
  35. 35. Odds and Ends • https://github.com/shr3kst3r/ansible- jenkins-example • You can reach me at dennis@wpengine.com or @shr3kst3r on the twitters

×