giraffesoft-chef 0.7.15
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +201 -0
- data/README.rdoc +135 -0
- data/bin/chef-client +26 -0
- data/bin/chef-solo +26 -0
- data/distro/debian/etc/init.d/chef-client +175 -0
- data/distro/debian/etc/init.d/chef-indexer +175 -0
- data/distro/debian/etc/init.d/chef-server +120 -0
- data/distro/debian/man/man1/chef-indexer.1 +42 -0
- data/distro/debian/man/man1/chef-server.1 +108 -0
- data/distro/debian/man/man8/chef-client.8 +61 -0
- data/distro/debian/man/man8/chef-solo.8 +58 -0
- data/distro/redhat/etc/chef/client.rb +16 -0
- data/distro/redhat/etc/chef/indexer.rb +10 -0
- data/distro/redhat/etc/chef/server.rb +22 -0
- data/distro/redhat/etc/init.d/chef-client +74 -0
- data/distro/redhat/etc/init.d/chef-indexer +76 -0
- data/distro/redhat/etc/init.d/chef-server +77 -0
- data/lib/chef.rb +49 -0
- data/lib/chef/application.rb +98 -0
- data/lib/chef/application/agent.rb +18 -0
- data/lib/chef/application/client.rb +209 -0
- data/lib/chef/application/indexer.rb +141 -0
- data/lib/chef/application/server.rb +18 -0
- data/lib/chef/application/solo.rb +214 -0
- data/lib/chef/client.rb +421 -0
- data/lib/chef/compile.rb +170 -0
- data/lib/chef/config.rb +141 -0
- data/lib/chef/cookbook.rb +171 -0
- data/lib/chef/cookbook/metadata.rb +407 -0
- data/lib/chef/cookbook/metadata/version.rb +87 -0
- data/lib/chef/cookbook_loader.rb +180 -0
- data/lib/chef/couchdb.rb +176 -0
- data/lib/chef/daemon.rb +170 -0
- data/lib/chef/exceptions.rb +36 -0
- data/lib/chef/file_cache.rb +205 -0
- data/lib/chef/log.rb +39 -0
- data/lib/chef/mixin/check_helper.rb +31 -0
- data/lib/chef/mixin/checksum.rb +37 -0
- data/lib/chef/mixin/command.rb +386 -0
- data/lib/chef/mixin/convert_to_class_name.rb +48 -0
- data/lib/chef/mixin/create_path.rb +56 -0
- data/lib/chef/mixin/deep_merge.rb +36 -0
- data/lib/chef/mixin/find_preferred_file.rb +92 -0
- data/lib/chef/mixin/from_file.rb +50 -0
- data/lib/chef/mixin/generate_url.rb +49 -0
- data/lib/chef/mixin/language.rb +79 -0
- data/lib/chef/mixin/params_validate.rb +197 -0
- data/lib/chef/mixin/recipe_definition_dsl_core.rb +77 -0
- data/lib/chef/mixin/template.rb +84 -0
- data/lib/chef/node.rb +406 -0
- data/lib/chef/node/attribute.rb +412 -0
- data/lib/chef/openid_registration.rb +181 -0
- data/lib/chef/platform.rb +254 -0
- data/lib/chef/provider.rb +101 -0
- data/lib/chef/provider/cron.rb +187 -0
- data/lib/chef/provider/deploy.rb +281 -0
- data/lib/chef/provider/deploy/revision.rb +70 -0
- data/lib/chef/provider/deploy/timestamped.rb +33 -0
- data/lib/chef/provider/directory.rb +72 -0
- data/lib/chef/provider/execute.rb +58 -0
- data/lib/chef/provider/file.rb +191 -0
- data/lib/chef/provider/git.rb +198 -0
- data/lib/chef/provider/group.rb +120 -0
- data/lib/chef/provider/group/gpasswd.rb +50 -0
- data/lib/chef/provider/group/groupadd.rb +78 -0
- data/lib/chef/provider/group/pw.rb +88 -0
- data/lib/chef/provider/group/usermod.rb +57 -0
- data/lib/chef/provider/http_request.rb +102 -0
- data/lib/chef/provider/ifconfig.rb +131 -0
- data/lib/chef/provider/link.rb +157 -0
- data/lib/chef/provider/mount.rb +117 -0
- data/lib/chef/provider/mount/mount.rb +208 -0
- data/lib/chef/provider/package.rb +160 -0
- data/lib/chef/provider/package/apt.rb +110 -0
- data/lib/chef/provider/package/dpkg.rb +109 -0
- data/lib/chef/provider/package/freebsd.rb +153 -0
- data/lib/chef/provider/package/macports.rb +105 -0
- data/lib/chef/provider/package/portage.rb +124 -0
- data/lib/chef/provider/package/rpm.rb +99 -0
- data/lib/chef/provider/package/rubygems.rb +136 -0
- data/lib/chef/provider/package/yum-dump.py +106 -0
- data/lib/chef/provider/package/yum.rb +175 -0
- data/lib/chef/provider/remote_directory.rb +126 -0
- data/lib/chef/provider/remote_file.rb +141 -0
- data/lib/chef/provider/route.rb +118 -0
- data/lib/chef/provider/ruby_block.rb +15 -0
- data/lib/chef/provider/script.rb +42 -0
- data/lib/chef/provider/service.rb +135 -0
- data/lib/chef/provider/service/debian.rb +64 -0
- data/lib/chef/provider/service/freebsd.rb +157 -0
- data/lib/chef/provider/service/gentoo.rb +54 -0
- data/lib/chef/provider/service/init.rb +71 -0
- data/lib/chef/provider/service/redhat.rb +62 -0
- data/lib/chef/provider/service/simple.rb +115 -0
- data/lib/chef/provider/subversion.rb +148 -0
- data/lib/chef/provider/template.rb +143 -0
- data/lib/chef/provider/user.rb +170 -0
- data/lib/chef/provider/user/pw.rb +113 -0
- data/lib/chef/provider/user/useradd.rb +107 -0
- data/lib/chef/queue.rb +145 -0
- data/lib/chef/recipe.rb +144 -0
- data/lib/chef/resource.rb +380 -0
- data/lib/chef/resource/apt_package.rb +34 -0
- data/lib/chef/resource/bash.rb +33 -0
- data/lib/chef/resource/cron.rb +179 -0
- data/lib/chef/resource/csh.rb +33 -0
- data/lib/chef/resource/deploy.rb +350 -0
- data/lib/chef/resource/deploy_revision.rb +35 -0
- data/lib/chef/resource/directory.rb +76 -0
- data/lib/chef/resource/dpkg_package.rb +34 -0
- data/lib/chef/resource/execute.rb +127 -0
- data/lib/chef/resource/file.rb +84 -0
- data/lib/chef/resource/gem_package.rb +41 -0
- data/lib/chef/resource/git.rb +36 -0
- data/lib/chef/resource/group.rb +70 -0
- data/lib/chef/resource/http_request.rb +52 -0
- data/lib/chef/resource/ifconfig.rb +134 -0
- data/lib/chef/resource/link.rb +78 -0
- data/lib/chef/resource/macports_package.rb +29 -0
- data/lib/chef/resource/mount.rb +135 -0
- data/lib/chef/resource/package.rb +80 -0
- data/lib/chef/resource/perl.rb +33 -0
- data/lib/chef/resource/portage_package.rb +33 -0
- data/lib/chef/resource/python.rb +33 -0
- data/lib/chef/resource/remote_directory.rb +91 -0
- data/lib/chef/resource/remote_file.rb +60 -0
- data/lib/chef/resource/route.rb +135 -0
- data/lib/chef/resource/ruby.rb +33 -0
- data/lib/chef/resource/ruby_block.rb +20 -0
- data/lib/chef/resource/scm.rb +129 -0
- data/lib/chef/resource/script.rb +51 -0
- data/lib/chef/resource/service.rb +134 -0
- data/lib/chef/resource/subversion.rb +33 -0
- data/lib/chef/resource/template.rb +60 -0
- data/lib/chef/resource/timestamped_deploy.rb +31 -0
- data/lib/chef/resource/user.rb +98 -0
- data/lib/chef/resource_collection.rb +204 -0
- data/lib/chef/resource_definition.rb +67 -0
- data/lib/chef/rest.rb +238 -0
- data/lib/chef/role.rb +231 -0
- data/lib/chef/run_list.rb +156 -0
- data/lib/chef/runner.rb +130 -0
- data/lib/chef/search.rb +88 -0
- data/lib/chef/search/result.rb +64 -0
- data/lib/chef/search_index.rb +77 -0
- data/lib/chef/tasks/chef_repo.rake +347 -0
- data/lib/chef/util/file_edit.rb +125 -0
- data/lib/chef/util/fileedit.rb +121 -0
- metadata +293 -0
data/lib/chef/search.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/search/result'
|
20
|
+
require 'ferret'
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
class Search
|
24
|
+
|
25
|
+
attr_reader :index
|
26
|
+
|
27
|
+
def initialize
|
28
|
+
@index = Ferret::Index::Index.new(:path => Chef::Config[:search_index_path])
|
29
|
+
end
|
30
|
+
|
31
|
+
def search(type, query="*", attributes=[], &block)
|
32
|
+
search_query = build_search_query(type, query)
|
33
|
+
start_time = Time.now
|
34
|
+
results = []
|
35
|
+
block ||= lambda { |b| b }
|
36
|
+
|
37
|
+
@index.search_each(search_query, :limit => :all) do |id, score|
|
38
|
+
results << block.call(build_hash(@index.doc(id)))
|
39
|
+
end
|
40
|
+
|
41
|
+
Chef::Log.debug("Search #{search_query} complete in #{Time.now - start_time} seconds")
|
42
|
+
|
43
|
+
attributes.empty? ? results : filter_by_attributes(results,attributes)
|
44
|
+
end
|
45
|
+
|
46
|
+
def filter_by_attributes(results, attributes)
|
47
|
+
results.collect do |r|
|
48
|
+
nr = Hash.new
|
49
|
+
nr[:index_name] = r[:index_name]
|
50
|
+
nr[:id] = r[:id]
|
51
|
+
attributes.each do |attrib|
|
52
|
+
if r.has_key?(attrib)
|
53
|
+
nr[attrib] = r[attrib]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
nr
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
private :filter_by_attributes
|
61
|
+
|
62
|
+
def list_indexes
|
63
|
+
indexes = Hash.new
|
64
|
+
@index.search_each("index_name:*", :limit => :all) do |id, score|
|
65
|
+
indexes[@index.doc(id)["index_name"]] = true
|
66
|
+
end
|
67
|
+
indexes.keys
|
68
|
+
end
|
69
|
+
|
70
|
+
def has_index?(index)
|
71
|
+
list_indexes.detect { |i| i == index }
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
def build_search_query(type, query)
|
76
|
+
query = "id:*" if query == '*'
|
77
|
+
"index_name:#{type} AND (#{query})"
|
78
|
+
end
|
79
|
+
|
80
|
+
def build_hash(doc)
|
81
|
+
result = Chef::Search::Result.new
|
82
|
+
doc.fields.each do |f|
|
83
|
+
result[f] = doc[f]
|
84
|
+
end
|
85
|
+
result
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'extlib'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Search
|
23
|
+
class Result
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
proc = lambda do |h,k|
|
27
|
+
newhash = Mash.new(&proc)
|
28
|
+
h.each do |pk, pv|
|
29
|
+
rx = /^#{k.to_s}_/
|
30
|
+
if pk =~ rx
|
31
|
+
newhash[ pk.gsub(rx,'') ] = pv
|
32
|
+
end
|
33
|
+
end
|
34
|
+
newhash
|
35
|
+
end
|
36
|
+
@internal = Mash.new(&proc)
|
37
|
+
end
|
38
|
+
|
39
|
+
def method_missing(symbol, *args, &block)
|
40
|
+
@internal.send(symbol, *args, &block)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Serialize this object as a hash
|
44
|
+
def to_json(*a)
|
45
|
+
result = {
|
46
|
+
'json_class' => self.class.name,
|
47
|
+
'results' => @internal
|
48
|
+
}
|
49
|
+
result.to_json(*a)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Create a Chef::Search::Result from JSON
|
53
|
+
def self.json_create(o)
|
54
|
+
result = self.new
|
55
|
+
o['results'].each do |k,v|
|
56
|
+
result[k] = v
|
57
|
+
end
|
58
|
+
result
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
|
@@ -0,0 +1,77 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'ferret'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class SearchIndex
|
23
|
+
|
24
|
+
attr_reader :index
|
25
|
+
|
26
|
+
def initialize
|
27
|
+
@index = Ferret::Index::Index.new(
|
28
|
+
:path => Chef::Config[:search_index_path],
|
29
|
+
:key => [ :id ]
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
def add(new_object)
|
34
|
+
index_hash = create_index_object(new_object)
|
35
|
+
Chef::Log.debug("Indexing #{index_hash[:index_name]} with #{index_hash.inspect}")
|
36
|
+
@index.add_document(index_hash)
|
37
|
+
end
|
38
|
+
|
39
|
+
def create_index_object(new_object)
|
40
|
+
index_hash = nil
|
41
|
+
|
42
|
+
if new_object.respond_to?(:to_index)
|
43
|
+
index_hash = new_object.to_index
|
44
|
+
elsif new_object.kind_of?(Hash)
|
45
|
+
index_hash = new_object
|
46
|
+
else
|
47
|
+
raise Chef::Exceptions::SearchIndex, "Cannot transform argument to a Hash!"
|
48
|
+
end
|
49
|
+
|
50
|
+
unless index_hash.has_key?(:index_name) || index_hash.has_key?("index_name")
|
51
|
+
raise Chef::Exceptions::SearchIndex, "Cannot index without an index_name key: #{index_hash.inspect}"
|
52
|
+
end
|
53
|
+
|
54
|
+
unless index_hash.has_key?(:id) || index_hash.has_key?("id")
|
55
|
+
raise Chef::Exceptions::SearchIndex, "Cannot index without an id key: #{index_hash.inspect}"
|
56
|
+
end
|
57
|
+
|
58
|
+
sanitized_hash = Hash.new
|
59
|
+
index_hash.each do |k,v|
|
60
|
+
sanitized_hash[k.to_sym] = v
|
61
|
+
end
|
62
|
+
|
63
|
+
sanitized_hash
|
64
|
+
end
|
65
|
+
|
66
|
+
def delete(index_obj)
|
67
|
+
to_delete = create_index_object(index_obj)
|
68
|
+
Chef::Log.debug("Removing #{to_delete.inspect} from the #{to_delete[:index_name]} index")
|
69
|
+
@index.delete(to_delete[:id])
|
70
|
+
end
|
71
|
+
|
72
|
+
def commit
|
73
|
+
@index.commit
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,347 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2008, 2009 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'rubygems'
|
20
|
+
require 'json'
|
21
|
+
require 'chef'
|
22
|
+
require 'chef/role'
|
23
|
+
require 'chef/cookbook/metadata'
|
24
|
+
require 'tempfile'
|
25
|
+
require 'rake'
|
26
|
+
|
27
|
+
desc "Update your repository from source control"
|
28
|
+
task :update do
|
29
|
+
puts "** Updating your repository"
|
30
|
+
|
31
|
+
case $vcs
|
32
|
+
when :svn
|
33
|
+
sh %{svn up}
|
34
|
+
when :git
|
35
|
+
pull = false
|
36
|
+
pull = true if File.join(TOPDIR, ".git", "remotes", "origin")
|
37
|
+
IO.foreach(File.join(TOPDIR, ".git", "config")) do |line|
|
38
|
+
pull = true if line =~ /\[remote "origin"\]/
|
39
|
+
end
|
40
|
+
if pull
|
41
|
+
sh %{git pull}
|
42
|
+
else
|
43
|
+
puts "* Skipping git pull, no origin specified"
|
44
|
+
end
|
45
|
+
else
|
46
|
+
puts "* No SCM configured, skipping update"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
desc "Test your cookbooks for syntax errors"
|
51
|
+
task :test_recipes do
|
52
|
+
puts "** Testing your cookbooks for syntax errors"
|
53
|
+
|
54
|
+
if File.exists?(TEST_CACHE)
|
55
|
+
cache = JSON.load(open(TEST_CACHE).read)
|
56
|
+
trap("INT") { puts "INT received, flushing test cache"; write_cache(cache) }
|
57
|
+
else
|
58
|
+
cache = {}
|
59
|
+
end
|
60
|
+
|
61
|
+
recipes = ["*cookbooks"].map { |folder|
|
62
|
+
Dir[File.join(TOPDIR, folder, "**", "*.rb")]
|
63
|
+
}.flatten
|
64
|
+
|
65
|
+
recipes.each do |recipe|
|
66
|
+
print "Testing recipe #{recipe}: "
|
67
|
+
|
68
|
+
recipe_mtime = File.stat(recipe).mtime.to_s
|
69
|
+
if cache.has_key?(recipe)
|
70
|
+
if cache[recipe]["mtime"] == recipe_mtime
|
71
|
+
puts "No modification since last test."
|
72
|
+
next
|
73
|
+
end
|
74
|
+
else
|
75
|
+
cache[recipe] = {}
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
sh %{ruby -c #{recipe}} do |ok, res|
|
80
|
+
if ok
|
81
|
+
cache[recipe]["mtime"] = recipe_mtime
|
82
|
+
else
|
83
|
+
write_cache(cache)
|
84
|
+
raise "Syntax error in #{recipe}"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
write_cache(cache)
|
90
|
+
end
|
91
|
+
|
92
|
+
desc "Test your templates for syntax errors"
|
93
|
+
task :test_templates do
|
94
|
+
puts "** Testing your cookbooks for syntax errors"
|
95
|
+
|
96
|
+
if File.exists?(TEST_CACHE)
|
97
|
+
cache = JSON.load(open(TEST_CACHE).read)
|
98
|
+
trap("INT") { puts "INT received, flushing test cache"; write_cache(cache) }
|
99
|
+
else
|
100
|
+
cache = {}
|
101
|
+
end
|
102
|
+
|
103
|
+
templates = ["*cookbooks"].map { |folder|
|
104
|
+
Dir[File.join(TOPDIR, folder, "**", "*.erb")]
|
105
|
+
}.flatten
|
106
|
+
|
107
|
+
templates.each do |template|
|
108
|
+
print "Testing template #{template}: "
|
109
|
+
|
110
|
+
template_mtime = File.stat(template).mtime.to_s
|
111
|
+
if cache.has_key?(template)
|
112
|
+
if cache[template]["mtime"] == template_mtime
|
113
|
+
puts "No change since last test."
|
114
|
+
next
|
115
|
+
end
|
116
|
+
else
|
117
|
+
cache[template] = {}
|
118
|
+
end
|
119
|
+
|
120
|
+
sh %{erubis -x #{template} | ruby -c} do |ok, res|
|
121
|
+
if ok
|
122
|
+
cache[template]["mtime"] = template_mtime
|
123
|
+
else
|
124
|
+
write_cache(cache)
|
125
|
+
raise "Syntax error in #{template}"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
write_cache(cache)
|
132
|
+
end
|
133
|
+
|
134
|
+
desc "Test your cookbooks for syntax errors"
|
135
|
+
task :test => [ :test_recipes , :test_templates ]
|
136
|
+
|
137
|
+
def write_cache(cache)
|
138
|
+
File.open(TEST_CACHE, "w") { |f| JSON.dump(cache, f) }
|
139
|
+
end
|
140
|
+
|
141
|
+
desc "Install the latest copy of the repository on this Chef Server"
|
142
|
+
task :install => [ :update, :test, :metadata, :roles ] do
|
143
|
+
puts "** Installing your cookbooks"
|
144
|
+
directories = [
|
145
|
+
COOKBOOK_PATH,
|
146
|
+
SITE_COOKBOOK_PATH,
|
147
|
+
CHEF_CONFIG_PATH
|
148
|
+
]
|
149
|
+
puts "* Creating Directories"
|
150
|
+
directories.each do |dir|
|
151
|
+
sh "sudo mkdir -p #{dir}"
|
152
|
+
sh "sudo chown root #{dir}"
|
153
|
+
end
|
154
|
+
puts "* Installing new Cookbooks"
|
155
|
+
sh "sudo rsync -rlP --delete --exclude '.svn' --exclude '.git*' cookbooks/ #{COOKBOOK_PATH}"
|
156
|
+
puts "* Installing new Site Cookbooks"
|
157
|
+
sh "sudo rsync -rlP --delete --exclude '.svn' --exclude '.git*' site-cookbooks/ #{SITE_COOKBOOK_PATH}"
|
158
|
+
puts "* Installing new Node Roles"
|
159
|
+
sh "sudo rsync -rlP --delete --exclude '.svn' --exclude '.git*' roles/ #{ROLE_PATH}"
|
160
|
+
|
161
|
+
if File.exists?(File.join(File.dirname(__FILE__), "config", "server.rb"))
|
162
|
+
puts "* Installing new Chef Server Config"
|
163
|
+
sh "sudo cp config/server.rb #{CHEF_SERVER_CONFIG}"
|
164
|
+
end
|
165
|
+
if File.exists?(File.join(File.dirname(__FILE__), "config", "client.rb"))
|
166
|
+
puts "* Installing new Chef Client Config"
|
167
|
+
sh "sudo cp config/client.rb #{CHEF_CLIENT_CONFIG}"
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
desc "By default, run rake test"
|
172
|
+
task :default => [ :test ]
|
173
|
+
|
174
|
+
desc "Create a new cookbook (with COOKBOOK=name, optional CB_PREFIX=site-)"
|
175
|
+
task :new_cookbook do
|
176
|
+
create_cookbook(File.join(TOPDIR, "#{ENV["CB_PREFIX"]}cookbooks"))
|
177
|
+
create_readme(File.join(TOPDIR, "#{ENV["CB_PREFIX"]}cookbooks"))
|
178
|
+
create_metadata(File.join(TOPDIR, "#{ENV["CB_PREFIX"]}cookbooks"))
|
179
|
+
end
|
180
|
+
|
181
|
+
def create_cookbook(dir)
|
182
|
+
raise "Must provide a COOKBOOK=" unless ENV["COOKBOOK"]
|
183
|
+
puts "** Creating cookbook #{ENV["COOKBOOK"]}"
|
184
|
+
sh "mkdir -p #{File.join(dir, ENV["COOKBOOK"], "attributes")}"
|
185
|
+
sh "mkdir -p #{File.join(dir, ENV["COOKBOOK"], "recipes")}"
|
186
|
+
sh "mkdir -p #{File.join(dir, ENV["COOKBOOK"], "definitions")}"
|
187
|
+
sh "mkdir -p #{File.join(dir, ENV["COOKBOOK"], "libraries")}"
|
188
|
+
sh "mkdir -p #{File.join(dir, ENV["COOKBOOK"], "resources")}"
|
189
|
+
sh "mkdir -p #{File.join(dir, ENV["COOKBOOK"], "providers")}"
|
190
|
+
sh "mkdir -p #{File.join(dir, ENV["COOKBOOK"], "files", "default")}"
|
191
|
+
sh "mkdir -p #{File.join(dir, ENV["COOKBOOK"], "templates", "default")}"
|
192
|
+
unless File.exists?(File.join(dir, ENV["COOKBOOK"], "recipes", "default.rb"))
|
193
|
+
open(File.join(dir, ENV["COOKBOOK"], "recipes", "default.rb"), "w") do |file|
|
194
|
+
file.puts <<-EOH
|
195
|
+
#
|
196
|
+
# Cookbook Name:: #{ENV["COOKBOOK"]}
|
197
|
+
# Recipe:: default
|
198
|
+
#
|
199
|
+
# Copyright #{Time.now.year}, #{COMPANY_NAME}
|
200
|
+
#
|
201
|
+
EOH
|
202
|
+
case NEW_COOKBOOK_LICENSE
|
203
|
+
when :apachev2
|
204
|
+
file.puts <<-EOH
|
205
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
206
|
+
# you may not use this file except in compliance with the License.
|
207
|
+
# You may obtain a copy of the License at
|
208
|
+
#
|
209
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
210
|
+
#
|
211
|
+
# Unless required by applicable law or agreed to in writing, software
|
212
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
213
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
214
|
+
# See the License for the specific language governing permissions and
|
215
|
+
# limitations under the License.
|
216
|
+
#
|
217
|
+
EOH
|
218
|
+
when :none
|
219
|
+
file.puts <<-EOH
|
220
|
+
# All rights reserved - Do Not Redistribute
|
221
|
+
#
|
222
|
+
EOH
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
def create_readme(dir)
|
229
|
+
raise "Must provide a COOKBOOK=" unless ENV["COOKBOOK"]
|
230
|
+
puts "** Creating README for cookbook: #{ENV["COOKBOOK"]}"
|
231
|
+
unless File.exists?(File.join(dir, ENV["COOKBOOK"], "README.rdoc"))
|
232
|
+
open(File.join(dir, ENV["COOKBOOK"], "README.rdoc"), "w") do |file|
|
233
|
+
file.puts <<-EOH
|
234
|
+
= DESCRIPTION:
|
235
|
+
|
236
|
+
= REQUIREMENTS:
|
237
|
+
|
238
|
+
= ATTRIBUTES:
|
239
|
+
|
240
|
+
= USAGE:
|
241
|
+
|
242
|
+
EOH
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
def create_metadata(dir)
|
248
|
+
raise "Must provide a COOKBOOK=" unless ENV["COOKBOOK"]
|
249
|
+
puts "** Creating metadata for cookbook: #{ENV["COOKBOOK"]}"
|
250
|
+
|
251
|
+
case NEW_COOKBOOK_LICENSE
|
252
|
+
when :apachev2
|
253
|
+
license = "Apache 2.0"
|
254
|
+
when :none
|
255
|
+
license = "All rights reserved"
|
256
|
+
end
|
257
|
+
|
258
|
+
unless File.exists?(File.join(dir, ENV["COOKBOOK"], "metadata.rb"))
|
259
|
+
open(File.join(dir, ENV["COOKBOOK"], "metadata.rb"), "w") do |file|
|
260
|
+
if File.exists?(File.join(dir, ENV["COOKBOOK"], 'README.rdoc'))
|
261
|
+
long_description = "long_description IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))"
|
262
|
+
end
|
263
|
+
file.puts <<-EOH
|
264
|
+
maintainer "#{COMPANY_NAME}"
|
265
|
+
maintainer_email "#{SSL_EMAIL_ADDRESS}"
|
266
|
+
license "#{license}"
|
267
|
+
description "Installs/Configures #{ENV["COOKBOOK"]}"
|
268
|
+
#{long_description}
|
269
|
+
version "0.1"
|
270
|
+
EOH
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
desc "Create a new self-signed SSL certificate for FQDN=foo.example.com"
|
276
|
+
task :ssl_cert do
|
277
|
+
$expect_verbose = true
|
278
|
+
fqdn = ENV["FQDN"]
|
279
|
+
fqdn =~ /^(.+?)\.(.+)$/
|
280
|
+
hostname = $1
|
281
|
+
domain = $2
|
282
|
+
raise "Must provide FQDN!" unless fqdn && hostname && domain
|
283
|
+
puts "** Creating self signed SSL Certificate for #{fqdn}"
|
284
|
+
sh("(cd #{CADIR} && openssl genrsa 2048 > #{fqdn}.key)")
|
285
|
+
sh("(cd #{CADIR} && chmod 644 #{fqdn}.key)")
|
286
|
+
puts "* Generating Self Signed Certificate Request"
|
287
|
+
tf = Tempfile.new("#{fqdn}.ssl-conf")
|
288
|
+
ssl_config = <<EOH
|
289
|
+
[ req ]
|
290
|
+
distinguished_name = req_distinguished_name
|
291
|
+
prompt = no
|
292
|
+
|
293
|
+
[ req_distinguished_name ]
|
294
|
+
C = #{SSL_COUNTRY_NAME}
|
295
|
+
ST = #{SSL_STATE_NAME}
|
296
|
+
L = #{SSL_LOCALITY_NAME}
|
297
|
+
O = #{COMPANY_NAME}
|
298
|
+
OU = #{SSL_ORGANIZATIONAL_UNIT_NAME}
|
299
|
+
CN = #{fqdn}
|
300
|
+
emailAddress = #{SSL_EMAIL_ADDRESS}
|
301
|
+
EOH
|
302
|
+
tf.puts(ssl_config)
|
303
|
+
tf.close
|
304
|
+
sh("(cd #{CADIR} && openssl req -config '#{tf.path}' -new -x509 -nodes -sha1 -days 3650 -key #{fqdn}.key > #{fqdn}.crt)")
|
305
|
+
sh("(cd #{CADIR} && openssl x509 -noout -fingerprint -text < #{fqdn}.crt > #{fqdn}.info)")
|
306
|
+
sh("(cd #{CADIR} && cat #{fqdn}.crt #{fqdn}.key > #{fqdn}.pem)")
|
307
|
+
sh("(cd #{CADIR} && chmod 644 #{fqdn}.pem)")
|
308
|
+
end
|
309
|
+
|
310
|
+
desc "Build cookbook metadata.json from metadata.rb"
|
311
|
+
task :metadata do
|
312
|
+
Chef::Config[:cookbook_path] = [ File.join(TOPDIR, 'cookbooks'), File.join(TOPDIR, 'site-cookbooks') ]
|
313
|
+
cl = Chef::CookbookLoader.new
|
314
|
+
cl.each do |cookbook|
|
315
|
+
if ENV['COOKBOOK']
|
316
|
+
next unless cookbook.name.to_s == ENV['COOKBOOK']
|
317
|
+
end
|
318
|
+
cook_meta = Chef::Cookbook::Metadata.new(cookbook)
|
319
|
+
Chef::Config.cookbook_path.each do |cdir|
|
320
|
+
metadata_rb_file = File.join(cdir, cookbook.name.to_s, 'metadata.rb')
|
321
|
+
metadata_json_file = File.join(cdir, cookbook.name.to_s, 'metadata.json')
|
322
|
+
if File.exists?(metadata_rb_file)
|
323
|
+
puts "Generating metadata for #{cookbook.name}"
|
324
|
+
cook_meta.from_file(metadata_rb_file)
|
325
|
+
File.open(metadata_json_file, "w") do |f|
|
326
|
+
f.write(JSON.pretty_generate(cook_meta))
|
327
|
+
end
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
desc "Build roles from roles/role_name.json from role_name.rb"
|
334
|
+
task :roles do
|
335
|
+
Chef::Config[:role_path] = File.join(TOPDIR, 'roles')
|
336
|
+
Dir[File.join(TOPDIR, 'roles', '**', '*.rb')].each do |role_file|
|
337
|
+
short_name = File.basename(role_file, '.rb')
|
338
|
+
puts "Generating role JSON for #{short_name}"
|
339
|
+
role = Chef::Role.new
|
340
|
+
role.name(short_name)
|
341
|
+
role.from_file(role_file)
|
342
|
+
File.open(File.join(TOPDIR, 'roles', "#{short_name}.json"), "w") do |f|
|
343
|
+
f.write(JSON.pretty_generate(role))
|
344
|
+
end
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|