Skip to content

Instantly share code, notes, and snippets.

@mikerowehl
Last active December 23, 2015 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikerowehl/6631010 to your computer and use it in GitHub Desktop.
Save mikerowehl/6631010 to your computer and use it in GitHub Desktop.
Rakefile with Chef upload_all and delete_all
require 'rubygems'
require 'chef'
require 'fileutils'
TOPDIR = File.expand_path(File.dirname(__FILE__))
load 'chef/tasks/chef_repo.rake'
environments = FileList[File.join(TOPDIR, 'environments', '*.json')].exclude(File.join(TOPDIR, 'environments', '_default.json'))
desc "Update environments"
task :environments => environments
environments.each do |fn|
task fn do
env = fn.pathmap('%f')
system("knife environment from file #{env}")
end
end
# The 'knife upload' command for roles only picks up .json files, so we need
# some custom handling.
rb_roles = FileList[File.join(TOPDIR, 'roles', '*.rb')]
desc "Update roles ending in .rb"
task :rb_roles => rb_roles
rb_roles.each do |fn|
task fn do
system("knife role from file #{fn}")
end
end
desc "Upload everything to the server"
task :upload_all => [ :environments, :rb_roles ] do
system("knife upload cookbooks")
system("knife upload roles")
system("knife upload data_bags")
end
desc "Remove everything from the current organization"
task :delete_all do
system('knife cookbook bulk delete "$" -y')
system('knife role bulk delete "$" -y')
system('for i in `knife data bag list`; do knife data bag delete $i -y; done')
system('for i in `knife environment list|grep -v "_default"`; do knife environment delete $i -y; done')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment