forked from datawrangling/chef-sample
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
69 lines (58 loc) · 2.24 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
REMOTE_CHEF_PATH = "/etc/chef" # Where to find upstream cookbooks
desc "Test your cookbooks and config files for syntax errors"
task :test do
Dir[ File.join(File.dirname(__FILE__), "**", "*.rb") ].each do |recipe|
sh %{ruby -c #{recipe}} do |ok, res|
raise "Syntax error in #{recipe}" if not ok
end
end
end
desc "Create dna from ruby file"
task :create_dna do
dna_file = File.join(File.dirname(__FILE__), "config", "dna.rb")
raise "There is no confit/dna.rb file! Take care of that!" unless File.exists? dna_file
sh "ruby #{dna_file}"
end
desc "Upload the latest copy of your cookbooks to remote server"
task :upload => [:test, :create_dna] do
if !ENV["server"]
puts "You need to specify a server rake upload server=whatever.com"
exit 1
end
puts "* Upload your cookbooks *"
sh "rsync -rlP --delete --exclude '.*' #{File.dirname(__FILE__)}/ #{ENV['server']}:#{REMOTE_CHEF_PATH}"
File.delete(File.dirname(__FILE__) + "/config/dna.json")
end
desc "Run chef solo on the server"
task :cook => [:upload] do
if !ENV["server"]
puts "You need to specify a server rake upload server=whatever.com"
exit 1
end
puts "* Running chef solo on remote server *"
sh "ssh #{ENV['server']} \"cd #{REMOTE_CHEF_PATH}; chef-solo -l debug -c config/solo.rb -j config/dna.json \""
end
desc "Create a new cookbook (with cookbook=name)"
task :new_cookbook do
create_cookbook(File.join(File.dirname(__FILE__), "cookbooks"))
end
def create_cookbook(dir)
raise "Must provide a COOKBOOK=" unless ENV["cookbook"]
puts "** Creating cookbook #{ENV["cookbook"]}"
sh "mkdir -p #{File.join(dir, ENV["cookbook"], "attributes")}"
sh "mkdir -p #{File.join(dir, ENV["cookbook"], "recipes")}"
sh "mkdir -p #{File.join(dir, ENV["cookbook"], "definitions")}"
sh "mkdir -p #{File.join(dir, ENV["cookbook"], "libraries")}"
sh "mkdir -p #{File.join(dir, ENV["cookbook"], "files", "default")}"
sh "mkdir -p #{File.join(dir, ENV["cookbook"], "templates", "default")}"
unless File.exists?(File.join(dir, ENV["cookbook"], "recipes", "default.rb"))
open(File.join(dir, ENV["cookbook"], "recipes", "default.rb"), "w") do |file|
file.puts <<-EOH
#
# Cookbook Name:: #{ENV["cookbook"]}
# Recipe:: default
#
EOH
end
end
end