chef 0.8.16 → 0.9.0.a3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of chef might be problematic. Click here for more details.
- data/bin/shef +1 -0
- data/distro/common/man/man1/chef-server-webui.1 +106 -0
- data/distro/common/man/man1/chef-server.1 +0 -1
- data/distro/common/man/man1/chef-solr-indexer.1 +55 -0
- data/distro/common/man/man1/chef-solr.1 +55 -0
- data/distro/common/man/man8/chef-client.8 +4 -2
- data/distro/common/man/man8/chef-solo.8 +1 -2
- data/distro/common/man/man8/chef-solr-rebuild.8 +37 -0
- data/distro/common/man/man8/knife.8 +668 -266
- data/distro/common/man/man8/shef.8 +45 -0
- data/distro/common/markdown/README +3 -0
- data/distro/common/markdown/knife.mkd +520 -0
- data/distro/debian/etc/default/chef-client +4 -0
- data/distro/debian/etc/default/chef-server +6 -0
- data/distro/debian/etc/default/chef-server-webui +6 -0
- data/distro/debian/etc/default/chef-solr +4 -0
- data/distro/debian/etc/default/chef-solr-indexer +4 -0
- data/distro/debian/etc/init.d/chef-client +41 -41
- data/distro/debian/etc/init.d/chef-server +10 -10
- data/distro/debian/etc/init.d/chef-server-webui +121 -0
- data/distro/debian/etc/init.d/chef-solr +177 -0
- data/distro/debian/etc/init.d/chef-solr-indexer +176 -0
- data/distro/redhat/etc/init.d/chef-client +76 -48
- data/distro/redhat/etc/init.d/chef-server +85 -51
- data/distro/redhat/etc/init.d/chef-server-webui +85 -51
- data/distro/redhat/etc/init.d/chef-solr +77 -49
- data/distro/redhat/etc/init.d/chef-solr-indexer +77 -48
- data/distro/redhat/etc/logrotate.d/chef-client +8 -0
- data/distro/redhat/etc/logrotate.d/chef-server +8 -0
- data/distro/redhat/etc/logrotate.d/chef-server-webui +8 -0
- data/distro/redhat/etc/logrotate.d/chef-solr +8 -0
- data/distro/redhat/etc/logrotate.d/chef-solr-indexer +8 -0
- data/distro/redhat/etc/sysconfig/chef-client +9 -4
- data/distro/redhat/etc/sysconfig/chef-server +10 -6
- data/distro/redhat/etc/sysconfig/chef-server-webui +10 -6
- data/distro/redhat/etc/sysconfig/chef-solr +3 -4
- data/distro/redhat/etc/sysconfig/chef-solr-indexer +3 -3
- data/lib/chef.rb +16 -5
- data/lib/chef/application/knife.rb +2 -2
- data/lib/chef/application/solo.rb +1 -7
- data/lib/chef/cache/checksum.rb +12 -5
- data/lib/chef/cache/file_cache_by_checksum.rb +52 -0
- data/lib/chef/checksum.rb +115 -0
- data/lib/chef/client.rb +193 -185
- data/lib/chef/config.rb +9 -1
- data/lib/chef/cookbook/cookbook_collection.rb +43 -0
- data/lib/chef/cookbook/file_system_file_vendor.rb +53 -0
- data/lib/chef/cookbook/file_vendor.rb +47 -0
- data/lib/chef/cookbook/metadata.rb +34 -35
- data/lib/chef/cookbook/metadata/version.rb +1 -1
- data/lib/chef/cookbook_loader.rb +70 -45
- data/lib/chef/cookbook_version.rb +760 -0
- data/lib/chef/couchdb.rb +8 -5
- data/lib/chef/data_bag_item.rb +5 -5
- data/lib/chef/exceptions.rb +10 -0
- data/lib/chef/file_access_control.rb +134 -0
- data/lib/chef/handler.rb +62 -0
- data/lib/chef/handler/json_file.rb +47 -0
- data/lib/chef/knife.rb +14 -2
- data/lib/chef/knife/bootstrap.rb +126 -0
- data/lib/chef/knife/cookbook_bulk_delete.rb +1 -1
- data/lib/chef/knife/cookbook_delete.rb +4 -4
- data/lib/chef/knife/cookbook_download.rb +57 -26
- data/lib/chef/knife/cookbook_metadata.rb +2 -2
- data/lib/chef/knife/cookbook_show.rb +30 -11
- data/lib/chef/knife/cookbook_upload.rb +113 -86
- data/lib/chef/knife/ec2_server_create.rb +146 -0
- data/lib/chef/knife/ec2_server_delete.rb +84 -0
- data/lib/chef/knife/ec2_server_list.rb +82 -0
- data/lib/chef/knife/status.rb +51 -0
- data/lib/chef/mixin/language_include_attribute.rb +16 -11
- data/lib/chef/mixin/language_include_recipe.rb +15 -16
- data/lib/chef/mixin/recipe_definition_dsl_core.rb +17 -20
- data/lib/chef/mixin/shell_out.rb +38 -0
- data/lib/chef/mixins.rb +1 -1
- data/lib/chef/node.rb +190 -63
- data/lib/chef/node/attribute.rb +92 -78
- data/lib/chef/platform.rb +24 -4
- data/lib/chef/provider.rb +28 -10
- data/lib/chef/provider/breakpoint.rb +2 -2
- data/lib/chef/provider/cookbook_file.rb +96 -0
- data/lib/chef/provider/cron.rb +2 -2
- data/lib/chef/provider/deploy.rb +12 -10
- data/lib/chef/provider/env.rb +152 -0
- data/lib/chef/provider/env/windows.rb +75 -0
- data/lib/chef/provider/file.rb +10 -14
- data/lib/chef/provider/group.rb +15 -2
- data/lib/chef/provider/group/dscl.rb +17 -25
- data/lib/chef/provider/group/gpasswd.rb +6 -3
- data/lib/chef/provider/group/pw.rb +3 -7
- data/lib/chef/provider/group/windows.rb +79 -0
- data/lib/chef/provider/link.rb +4 -5
- data/lib/chef/provider/mdadm.rb +25 -18
- data/lib/chef/provider/mount/mount.rb +28 -27
- data/lib/chef/provider/package.rb +35 -35
- data/lib/chef/provider/package/dpkg.rb +13 -10
- data/lib/chef/provider/package/easy_install.rb +6 -6
- data/lib/chef/provider/package/freebsd.rb +17 -51
- data/lib/chef/provider/package/rpm.rb +1 -1
- data/lib/chef/provider/package/rubygems.rb +391 -74
- data/lib/chef/provider/package/yum.rb +2 -2
- data/lib/chef/provider/package/zypper.rb +2 -1
- data/lib/chef/provider/remote_directory.rb +60 -83
- data/lib/chef/provider/remote_file.rb +17 -66
- data/lib/chef/provider/script.rb +20 -9
- data/lib/chef/provider/service.rb +23 -30
- data/lib/chef/provider/service/arch.rb +3 -3
- data/lib/chef/provider/service/debian.rb +22 -17
- data/lib/chef/provider/service/freebsd.rb +4 -4
- data/lib/chef/provider/service/init.rb +2 -2
- data/lib/chef/provider/service/redhat.rb +14 -16
- data/lib/chef/provider/service/simple.rb +7 -3
- data/lib/chef/provider/service/solaris.rb +85 -0
- data/lib/chef/provider/service/upstart.rb +12 -7
- data/lib/chef/provider/service/windows.rb +2 -2
- data/lib/chef/provider/template.rb +133 -118
- data/lib/chef/provider/user.rb +34 -17
- data/lib/chef/provider/user/dscl.rb +117 -114
- data/lib/chef/provider/user/windows.rb +124 -0
- data/lib/chef/providers.rb +7 -0
- data/lib/chef/recipe.rb +39 -20
- data/lib/chef/resource.rb +47 -52
- data/lib/chef/resource/apt_package.rb +4 -4
- data/lib/chef/resource/bash.rb +4 -4
- data/lib/chef/resource/cookbook_file.rb +45 -0
- data/lib/chef/resource/cron.rb +3 -3
- data/lib/chef/resource/csh.rb +4 -4
- data/lib/chef/resource/deploy.rb +3 -3
- data/lib/chef/resource/directory.rb +4 -4
- data/lib/chef/resource/dpkg_package.rb +4 -4
- data/lib/chef/resource/easy_install_package.rb +3 -3
- data/lib/chef/resource/env.rb +58 -0
- data/lib/chef/resource/erl_call.rb +3 -3
- data/lib/chef/resource/execute.rb +3 -3
- data/lib/chef/resource/file.rb +3 -3
- data/lib/chef/resource/freebsd_package.rb +3 -3
- data/lib/chef/resource/gem_package.rb +17 -9
- data/lib/chef/resource/git.rb +3 -3
- data/lib/chef/resource/group.rb +3 -3
- data/lib/chef/resource/http_request.rb +4 -4
- data/lib/chef/resource/ifconfig.rb +3 -3
- data/lib/chef/resource/link.rb +3 -3
- data/lib/chef/resource/log.rb +2 -2
- data/lib/chef/resource/macports_package.rb +2 -2
- data/lib/chef/resource/mdadm.rb +3 -3
- data/lib/chef/resource/mount.rb +2 -2
- data/lib/chef/resource/package.rb +4 -4
- data/lib/chef/resource/pacman_package.rb +4 -4
- data/lib/chef/resource/perl.rb +4 -4
- data/lib/chef/resource/portage_package.rb +4 -4
- data/lib/chef/resource/python.rb +4 -4
- data/lib/chef/resource/remote_directory.rb +3 -3
- data/lib/chef/resource/remote_file.rb +26 -3
- data/lib/chef/resource/route.rb +3 -3
- data/lib/chef/resource/ruby.rb +3 -3
- data/lib/chef/resource/ruby_block.rb +3 -2
- data/lib/chef/resource/scm.rb +7 -5
- data/lib/chef/resource/script.rb +4 -4
- data/lib/chef/resource/service.rb +3 -3
- data/lib/chef/resource/subversion.rb +4 -2
- data/lib/chef/resource/template.rb +3 -3
- data/lib/chef/resource/user.rb +3 -3
- data/lib/chef/resource/yum_package.rb +3 -3
- data/lib/chef/resource_collection.rb +9 -5
- data/lib/chef/resources.rb +2 -0
- data/lib/chef/rest.rb +4 -0
- data/lib/chef/role.rb +2 -0
- data/lib/chef/run_context.rb +108 -0
- data/lib/chef/run_list.rb +75 -98
- data/lib/chef/run_list/run_list_expansion.rb +156 -0
- data/lib/chef/run_list/run_list_item.rb +71 -0
- data/lib/chef/runner.rb +58 -61
- data/lib/chef/sandbox.rb +147 -0
- data/lib/chef/shef.rb +4 -3
- data/lib/chef/shef/ext.rb +12 -4
- data/lib/chef/shef/shef_session.rb +27 -23
- data/lib/chef/shell_out.rb +375 -0
- data/lib/chef/util/windows.rb +56 -0
- data/lib/chef/util/windows/net_group.rb +101 -0
- data/lib/chef/util/windows/net_user.rb +198 -0
- data/lib/chef/version.rb +20 -0
- metadata +112 -22
- data/lib/chef/compile.rb +0 -158
- data/lib/chef/cookbook.rb +0 -201
- data/lib/chef/mixin/generate_url.rb +0 -58
data/lib/chef/provider/cron.rb
CHANGED
@@ -27,8 +27,8 @@ class Chef
|
|
27
27
|
|
28
28
|
CRON_PATTERN = /([0-9\*\-\,\/]+)\s*([0-9\*\-\,\/]+)\s*([0-9\*\-\,\/]+)\s*([0-9\*\-\,\/]+)\s*([0-9\*\-\,\/]+)\s*(.*)/
|
29
29
|
|
30
|
-
def initialize(
|
31
|
-
super(
|
30
|
+
def initialize(new_resource, run_context)
|
31
|
+
super(new_resource, run_context)
|
32
32
|
@cron_exists = false
|
33
33
|
@cron_empty = false
|
34
34
|
end
|
data/lib/chef/provider/deploy.rb
CHANGED
@@ -30,14 +30,10 @@ class Chef
|
|
30
30
|
|
31
31
|
attr_reader :scm_provider, :release_path
|
32
32
|
|
33
|
-
def initialize(
|
34
|
-
super(
|
33
|
+
def initialize(new_resource, run_context)
|
34
|
+
super(new_resource, run_context)
|
35
35
|
|
36
|
-
|
37
|
-
@definitions ||= Hash.new
|
38
|
-
@collection = Chef::ResourceCollection.new
|
39
|
-
|
40
|
-
@scm_provider = @new_resource.scm_provider.new(@node, @new_resource)
|
36
|
+
@scm_provider = new_resource.scm_provider.new(new_resource, run_context)
|
41
37
|
|
42
38
|
# @configuration is not used by Deploy, it is only for backwards compat with
|
43
39
|
# chef-deploy or capistrano hooks that might use it to get environment information
|
@@ -275,17 +271,23 @@ class Chef
|
|
275
271
|
end
|
276
272
|
|
277
273
|
def install_gems
|
274
|
+
gem_resource_collection_runner.converge
|
275
|
+
end
|
276
|
+
|
277
|
+
def gem_resource_collection_runner
|
278
278
|
gems_collection = Chef::ResourceCollection.new
|
279
279
|
gem_packages.each { |rbgem| gems_collection << rbgem }
|
280
|
-
|
280
|
+
gems_run_context = run_context.dup
|
281
|
+
gems_run_context.resource_collection = gems_collection
|
282
|
+
Chef::Runner.new(gems_run_context)
|
281
283
|
end
|
282
|
-
|
284
|
+
|
283
285
|
def gem_packages
|
284
286
|
return [] unless ::File.exist?("#{release_path}/gems.yml")
|
285
287
|
gems = YAML.load(IO.read("#{release_path}/gems.yml"))
|
286
288
|
|
287
289
|
gems.map do |g|
|
288
|
-
r = Chef::Resource::GemPackage.new(g[:name]
|
290
|
+
r = Chef::Resource::GemPackage.new(g[:name])
|
289
291
|
r.version g[:version]
|
290
292
|
r.action :install
|
291
293
|
r.source "http://gems.github.com"
|
@@ -0,0 +1,152 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Doug MacEachern (<dougm@vmware.com>)
|
3
|
+
# Copyright:: Copyright (c) 2010 VMware, 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/provider'
|
20
|
+
require 'chef/mixin/command'
|
21
|
+
require 'chef/resource/env'
|
22
|
+
|
23
|
+
class Chef
|
24
|
+
class Provider
|
25
|
+
class Env < Chef::Provider
|
26
|
+
include Chef::Mixin::Command
|
27
|
+
attr_accessor :key_exists
|
28
|
+
|
29
|
+
def initialize(new_resource, run_context)
|
30
|
+
super
|
31
|
+
@key_exists = true
|
32
|
+
end
|
33
|
+
|
34
|
+
def load_current_resource
|
35
|
+
@current_resource = Chef::Resource::Env.new(@new_resource.name)
|
36
|
+
@current_resource.key_name(@new_resource.key_name)
|
37
|
+
|
38
|
+
if env_key_exists(@new_resource.key_name)
|
39
|
+
@current_resource.value(env_value(@new_resource.key_name))
|
40
|
+
else
|
41
|
+
@key_exists = false
|
42
|
+
Chef::Log.debug("#{@new_resource}: key does not exist")
|
43
|
+
end
|
44
|
+
|
45
|
+
@current_resource
|
46
|
+
end
|
47
|
+
|
48
|
+
def env_value(key_name)
|
49
|
+
raise Chef::Exceptions::Env, "#{@new_resource} - #{self.to_s} provider does not implement env_value!"
|
50
|
+
end
|
51
|
+
|
52
|
+
def env_key_exists(key_name)
|
53
|
+
env_value(key_name) ? true : false
|
54
|
+
end
|
55
|
+
|
56
|
+
# Check to see if value needs any changes
|
57
|
+
#
|
58
|
+
# ==== Returns
|
59
|
+
# <true>:: If a change is required
|
60
|
+
# <false>:: If a change is not required
|
61
|
+
def compare_value
|
62
|
+
if @new_resource.delim
|
63
|
+
#e.g. check for existing value within PATH
|
64
|
+
not @current_resource.value.split(@new_resource.delim).any? do |val|
|
65
|
+
val == @new_resource.value
|
66
|
+
end
|
67
|
+
else
|
68
|
+
@new_resource.value != @current_resource.value
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def action_create
|
73
|
+
if @key_exists
|
74
|
+
if compare_value
|
75
|
+
modify_env
|
76
|
+
Chef::Log.info("Altered #{@new_resource}")
|
77
|
+
@new_resource.updated = true
|
78
|
+
end
|
79
|
+
else
|
80
|
+
create_env
|
81
|
+
Chef::Log.debug("Created #{@new_resource}")
|
82
|
+
@new_resource.updated = true
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
#e.g. delete a PATH element
|
87
|
+
#
|
88
|
+
# ==== Returns
|
89
|
+
# <true>:: If we handled the element case and caller should not delete the key
|
90
|
+
# <false>:: Caller should delete the key, either no :delim was specific or value was empty
|
91
|
+
# after we removed the element.
|
92
|
+
def delete_element
|
93
|
+
return false unless @new_resource.delim #no delim: delete the key
|
94
|
+
if compare_value
|
95
|
+
Chef::Log.debug("#{@new_resource}: element '#{@new_resource.value}' does not exist")
|
96
|
+
return true #do not delete the key
|
97
|
+
else
|
98
|
+
new_value =
|
99
|
+
@current_resource.value.split(@new_resource.delim).select { |item|
|
100
|
+
item != @new_resource.value
|
101
|
+
}.join(@new_resource.delim)
|
102
|
+
|
103
|
+
if new_value.empty?
|
104
|
+
return false #nothing left here, delete the key
|
105
|
+
else
|
106
|
+
old_value = @new_resource.value(new_value)
|
107
|
+
create_env
|
108
|
+
Chef::Log.debug("Deleted #{old_value} element")
|
109
|
+
@new_resource.updated = true
|
110
|
+
return true #we removed the element and updated; do not delete the key
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def action_delete
|
116
|
+
if @key_exists && !delete_element
|
117
|
+
delete_env
|
118
|
+
Chef::Log.debug("Deleted #{@new_resource}")
|
119
|
+
@new_resource.updated = true
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def action_modify
|
124
|
+
if @key_exists
|
125
|
+
if compare_value
|
126
|
+
modify_env
|
127
|
+
@new_resource.updated = true
|
128
|
+
Chef::Log.info("Modified #{@new_resource}")
|
129
|
+
end
|
130
|
+
else
|
131
|
+
raise Chef::Exceptions::Env, "Cannot modify #{@new_resource} - key does not exist!"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def create_env
|
136
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :#{@new_resource.action}"
|
137
|
+
end
|
138
|
+
|
139
|
+
def delete_env
|
140
|
+
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :delete"
|
141
|
+
end
|
142
|
+
|
143
|
+
def modify_env
|
144
|
+
if @new_resource.delim
|
145
|
+
#e.g. add to PATH
|
146
|
+
@new_resource.value << @new_resource.delim << @current_resource.value
|
147
|
+
end
|
148
|
+
create_env
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Doug MacEachern (<dougm@vmware.com>)
|
3
|
+
# Copyright:: Copyright (c) 2010 VMware, 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
|
+
if RUBY_PLATFORM =~ /mswin|mingw32|windows/
|
20
|
+
require 'ruby-wmi'
|
21
|
+
require 'Win32API'
|
22
|
+
end
|
23
|
+
|
24
|
+
class Chef
|
25
|
+
class Provider
|
26
|
+
class Env
|
27
|
+
class Windows < Chef::Provider::Env
|
28
|
+
|
29
|
+
def create_env
|
30
|
+
obj = env_obj(@new_resource.key_name)
|
31
|
+
unless obj
|
32
|
+
obj = WIN32OLE.connect("winmgmts://").get("Win32_Environment").spawninstance_
|
33
|
+
obj.name = @new_resource.key_name
|
34
|
+
obj.username = "<System>"
|
35
|
+
end
|
36
|
+
obj.variablevalue = @new_resource.value
|
37
|
+
obj.put_
|
38
|
+
broadcast_env_change
|
39
|
+
end
|
40
|
+
|
41
|
+
def delete_env
|
42
|
+
obj = env_obj(@new_resource.key_name)
|
43
|
+
if obj
|
44
|
+
obj.delete_
|
45
|
+
broadcast_env_change
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def env_value(key_name)
|
50
|
+
obj = env_obj(key_name)
|
51
|
+
return obj ? obj.variablevalue : nil
|
52
|
+
end
|
53
|
+
|
54
|
+
def env_obj(key_name)
|
55
|
+
WMI::Win32_Environment.find(:first,
|
56
|
+
:conditions => { :name => key_name })
|
57
|
+
end
|
58
|
+
|
59
|
+
#see: http://msdn.microsoft.com/en-us/library/ms682653%28VS.85%29.aspx
|
60
|
+
HWND_BROADCAST = 0xffff
|
61
|
+
WM_SETTINGCHANGE = 0x001A
|
62
|
+
SMTO_BLOCK = 0x0001
|
63
|
+
SMTO_ABORTIFHUNG = 0x0002
|
64
|
+
SMTO_NOTIMEOUTIFNOTHUNG = 0x0008
|
65
|
+
|
66
|
+
def broadcast_env_change
|
67
|
+
result = 0
|
68
|
+
flags = SMTO_BLOCK | SMTO_ABORTIFHUNG | SMTO_NOTIMEOUTIFNOTHUNG
|
69
|
+
@send_message ||= Win32API.new('user32', 'SendMessageTimeout', 'LLLPLLP', 'L')
|
70
|
+
@send_message.call(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 'Environment', flags, 5000, result)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/chef/provider/file.rb
CHANGED
@@ -20,7 +20,6 @@ require 'chef/config'
|
|
20
20
|
require 'chef/log'
|
21
21
|
require 'chef/resource/file'
|
22
22
|
require 'chef/mixin/checksum'
|
23
|
-
require 'chef/mixin/generate_url'
|
24
23
|
require 'chef/provider'
|
25
24
|
require 'etc'
|
26
25
|
require 'fileutils'
|
@@ -29,7 +28,6 @@ class Chef
|
|
29
28
|
class Provider
|
30
29
|
class File < Chef::Provider
|
31
30
|
include Chef::Mixin::Checksum
|
32
|
-
include Chef::Mixin::GenerateURL
|
33
31
|
|
34
32
|
def negative_complement(big)
|
35
33
|
if big > 1073741823 # Fixnum max
|
@@ -67,6 +65,7 @@ class Chef
|
|
67
65
|
def set_content
|
68
66
|
unless compare_content
|
69
67
|
Chef::Log.info("Setting content for #{@new_resource}")
|
68
|
+
backup @new_resource.path if ::File.exists?(@new_resource.path)
|
70
69
|
::File.open(@new_resource.path, "w") {|f| f.write @new_resource.content }
|
71
70
|
@new_resource.updated = true
|
72
71
|
end
|
@@ -181,16 +180,18 @@ class Chef
|
|
181
180
|
time = Time.now
|
182
181
|
savetime = time.strftime("%Y%m%d%H%M%S")
|
183
182
|
backup_filename = "#{@new_resource.path}.chef-#{savetime}"
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
FileUtils.
|
183
|
+
# if :file_backup_path is nil, we fallback to the old behavior of
|
184
|
+
# keeping the backup in the same directory. We also need to to_s it
|
185
|
+
# so we don't get a type error around implicit to_str conversions.
|
186
|
+
prefix = Chef::Config[:file_backup_path].to_s
|
187
|
+
backup_path = ::File.join(prefix, backup_filename)
|
188
|
+
FileUtils.mkdir_p(::File.dirname(backup_path)) if Chef::Config[:file_backup_path]
|
189
|
+
Chef::Log.info("Backing up #{@new_resource} to #{backup_path}")
|
190
|
+
FileUtils.cp(file, backup_path, :preserve => true)
|
190
191
|
|
191
192
|
# Clean up after the number of backups
|
192
193
|
slice_number = @new_resource.backup
|
193
|
-
backup_files = Dir[prefix
|
194
|
+
backup_files = Dir[::File.join(prefix, ".#{@new_resource.path}.chef-*")].sort { |a,b| b <=> a }
|
194
195
|
if backup_files.length >= @new_resource.backup
|
195
196
|
remainder = backup_files.slice(slice_number..-1)
|
196
197
|
remainder.each do |backup_to_delete|
|
@@ -201,11 +202,6 @@ class Chef
|
|
201
202
|
end
|
202
203
|
end
|
203
204
|
|
204
|
-
def generate_url(url, type, args=nil)
|
205
|
-
cookbook_name = (@new_resource.respond_to?(:cookbook) && @new_resource.cookbook) ? @new_resource.cookbook : @new_resource.cookbook_name
|
206
|
-
generate_cookbook_url(url, cookbook_name, type, @node, args)
|
207
|
-
end
|
208
|
-
|
209
205
|
private
|
210
206
|
|
211
207
|
def new_resource_content_checksum
|
data/lib/chef/provider/group.rb
CHANGED
@@ -27,8 +27,8 @@ class Chef
|
|
27
27
|
include Chef::Mixin::Command
|
28
28
|
attr_accessor :group_exists
|
29
29
|
|
30
|
-
def initialize(
|
31
|
-
super
|
30
|
+
def initialize(new_resource, run_context)
|
31
|
+
super
|
32
32
|
@group_exists = true
|
33
33
|
end
|
34
34
|
|
@@ -115,6 +115,19 @@ class Chef
|
|
115
115
|
raise Chef::Exceptions::Group, "Cannot modify #{@new_resource} - group does not exist!"
|
116
116
|
end
|
117
117
|
end
|
118
|
+
|
119
|
+
def create_group
|
120
|
+
raise NotImplementedError, "subclasses of Chef::Provider::Group should define #create_group"
|
121
|
+
end
|
122
|
+
|
123
|
+
def manage_group
|
124
|
+
raise NotImplementedError, "subclasses of Chef::Provider::Group should define #manage_group"
|
125
|
+
end
|
126
|
+
|
127
|
+
def remove_group
|
128
|
+
raise NotImplementedError, "subclasses of Chef::Provider::Group should define #remove_group"
|
129
|
+
end
|
130
|
+
|
118
131
|
end
|
119
132
|
end
|
120
133
|
end
|
@@ -73,6 +73,7 @@ class Chef
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def set_members
|
76
|
+
pp :set_members => {:append => @new_resource.append, :members => @new_resource.members}
|
76
77
|
unless @new_resource.append
|
77
78
|
Chef::Log.debug("#{@new_resource}: removing group members #{@current_resource.members.join(' ')}") unless @current_resource.members.empty?
|
78
79
|
safe_dscl("create /Groups/#{@new_resource.group_name} GroupMembers ''") # clear guid list
|
@@ -90,35 +91,26 @@ class Chef
|
|
90
91
|
end
|
91
92
|
|
92
93
|
def create_group
|
93
|
-
|
94
|
+
dscl_create_group
|
95
|
+
set_gid
|
96
|
+
set_members
|
94
97
|
end
|
95
98
|
|
96
|
-
def manage_group
|
97
|
-
|
98
|
-
|
99
|
-
[:group_name,:gid,:members].each do |field|
|
100
|
-
if @current_resource.send(field) != @new_resource.send(field)
|
101
|
-
fields << field if @new_resource.send(field)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
else
|
105
|
-
# create
|
106
|
-
fields = [:group_name,:gid,:members]
|
99
|
+
def manage_group
|
100
|
+
if @new_resource.group_name && (@current_resource.group_name != @new_resource.group_name)
|
101
|
+
dscl_create_group
|
107
102
|
end
|
108
|
-
|
109
|
-
|
110
|
-
case field
|
111
|
-
when :group_name
|
112
|
-
safe_dscl("create /Groups/#{@new_resource.group_name}")
|
113
|
-
safe_dscl("create /Groups/#{@new_resource.group_name} Password '*'")
|
114
|
-
|
115
|
-
when :gid
|
116
|
-
set_gid
|
117
|
-
|
118
|
-
when :members
|
119
|
-
set_members
|
120
|
-
end
|
103
|
+
if @new_resource.gid && (@current_resource.gid != @new_resource.gid)
|
104
|
+
set_gid
|
121
105
|
end
|
106
|
+
if @new_resource.members && (@current_resource.members != @new_resource.members)
|
107
|
+
set_members
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def dscl_create_group
|
112
|
+
safe_dscl("create /Groups/#{@new_resource.group_name}")
|
113
|
+
safe_dscl("create /Groups/#{@new_resource.group_name} Password '*'")
|
122
114
|
end
|
123
115
|
|
124
116
|
def remove_group
|
@@ -17,12 +17,15 @@
|
|
17
17
|
#
|
18
18
|
|
19
19
|
require 'chef/provider/group/groupadd'
|
20
|
+
require 'chef/mixin/shell_out'
|
20
21
|
|
21
22
|
class Chef
|
22
23
|
class Provider
|
23
24
|
class Group
|
24
25
|
class Gpasswd < Chef::Provider::Group::Groupadd
|
25
|
-
|
26
|
+
|
27
|
+
include Chef::Mixin::ShellOut
|
28
|
+
|
26
29
|
def load_current_resource
|
27
30
|
super
|
28
31
|
|
@@ -34,11 +37,11 @@ class Chef
|
|
34
37
|
if(@new_resource.append)
|
35
38
|
@new_resource.members.each do |member|
|
36
39
|
Chef::Log.debug("#{@new_resource}: appending member #{member} to group #{@new_resource.group_name}")
|
37
|
-
|
40
|
+
shell_out!("gpasswd -a #{member} #{@new_resource.group_name}")
|
38
41
|
end
|
39
42
|
else
|
40
43
|
Chef::Log.debug("#{@new_resource}: setting group members to #{@new_resource.members.join(', ')}")
|
41
|
-
|
44
|
+
shell_out!("gpasswd -M #{@new_resource.members.join(',')} #{@new_resource.group_name}")
|
42
45
|
end
|
43
46
|
else
|
44
47
|
Chef::Log.debug("#{@new_resource}: not changing group members, the group has no members")
|