Rakefile with Chef upload_all and delete_all
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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