Skip to content

Instantly share code, notes, and snippets.

@jodell
Created June 19, 2012 22:00
Show Gist options
  • Save jodell/2956791 to your computer and use it in GitHub Desktop.
Save jodell/2956791 to your computer and use it in GitHub Desktop.
Simple CI script for a Chef repo/server
#!/bin/bash
# This script provides a continuous devops loop between cookbook authoring,
# deployment to a chef-server, and verification of successful chef runs.
# Bootstrapping
bundle check || bundle --deployment --path=/var/lib/jenkins/shared/vendor_bundle
# Upload chef cookbooks & roles to the chef-server.
bundle exec rake upload:all
# Via the chef server, query all managed nodes and as root, kick off a chef-client run immediately.
#
# HACK: `knife ssh` doesn't forward exit status like it probably should. Since it always returns
# zero, we will have to instrument a marker and grep for it.
# SEE http://tickets.opscode.com/browse/CHEF-2627
#
VERBOSE=${VERBOSE:-info}
knife ssh *:* -x root ". /etc/profile && chef-client -l $VERBOSE || echo 'CHEF RUN FAILED'" | tee /tmp/chef-run
! grep -q 'CHEF RUN FAILED' /tmp/chef-run
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment