runa-chef 0.8.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +201 -0
- data/README.rdoc +136 -0
- data/bin/chef-client +26 -0
- data/bin/chef-solo +26 -0
- data/bin/knife +27 -0
- data/bin/shef +45 -0
- data/distro/README +2 -0
- data/distro/common/man/man1/chef-indexer.1 +42 -0
- data/distro/common/man/man1/chef-server.1 +108 -0
- data/distro/common/man/man8/chef-client.8 +61 -0
- data/distro/common/man/man8/chef-solo.8 +58 -0
- data/distro/common/man/man8/knife.8 +359 -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/redhat/etc/init.d/chef-client +78 -0
- data/distro/redhat/etc/init.d/chef-indexer +76 -0
- data/distro/redhat/etc/init.d/chef-server +78 -0
- data/distro/redhat/etc/sysconfig/chef-client +10 -0
- data/distro/redhat/etc/sysconfig/chef-indexer +8 -0
- data/distro/redhat/etc/sysconfig/chef-server +10 -0
- data/distro/suse/etc/init.d/chef-client +121 -0
- data/lib/chef.rb +49 -0
- data/lib/chef/api_client.rb +269 -0
- data/lib/chef/application.rb +98 -0
- data/lib/chef/application/agent.rb +18 -0
- data/lib/chef/application/client.rb +214 -0
- data/lib/chef/application/knife.rb +138 -0
- data/lib/chef/application/server.rb +19 -0
- data/lib/chef/application/solo.rb +214 -0
- data/lib/chef/cache.rb +61 -0
- data/lib/chef/cache/checksum.rb +70 -0
- data/lib/chef/certificate.rb +154 -0
- data/lib/chef/client.rb +323 -0
- data/lib/chef/compile.rb +158 -0
- data/lib/chef/config.rb +195 -0
- data/lib/chef/cookbook.rb +198 -0
- data/lib/chef/cookbook/metadata.rb +487 -0
- data/lib/chef/cookbook/metadata/version.rb +87 -0
- data/lib/chef/cookbook_loader.rb +180 -0
- data/lib/chef/couchdb.rb +273 -0
- data/lib/chef/daemon.rb +170 -0
- data/lib/chef/data_bag.rb +216 -0
- data/lib/chef/data_bag_item.rb +227 -0
- data/lib/chef/exceptions.rb +39 -0
- data/lib/chef/file_cache.rb +205 -0
- data/lib/chef/knife.rb +300 -0
- data/lib/chef/knife/client_bulk_delete.rb +41 -0
- data/lib/chef/knife/client_create.rb +55 -0
- data/lib/chef/knife/client_delete.rb +37 -0
- data/lib/chef/knife/client_edit.rb +37 -0
- data/lib/chef/knife/client_list.rb +40 -0
- data/lib/chef/knife/client_reregister.rb +48 -0
- data/lib/chef/knife/client_show.rb +42 -0
- data/lib/chef/knife/configure.rb +84 -0
- data/lib/chef/knife/cookbook_bulk_delete.rb +47 -0
- data/lib/chef/knife/cookbook_delete.rb +41 -0
- data/lib/chef/knife/cookbook_download.rb +57 -0
- data/lib/chef/knife/cookbook_list.rb +41 -0
- data/lib/chef/knife/cookbook_metadata.rb +87 -0
- data/lib/chef/knife/cookbook_show.rb +75 -0
- data/lib/chef/knife/cookbook_upload.rb +173 -0
- data/lib/chef/knife/data_bag_create.rb +43 -0
- data/lib/chef/knife/data_bag_delete.rb +43 -0
- data/lib/chef/knife/data_bag_edit.rb +49 -0
- data/lib/chef/knife/data_bag_list.rb +42 -0
- data/lib/chef/knife/data_bag_show.rb +40 -0
- data/lib/chef/knife/ec2_instance_data.rb +46 -0
- data/lib/chef/knife/node_bulk_delete.rb +44 -0
- data/lib/chef/knife/node_create.rb +39 -0
- data/lib/chef/knife/node_delete.rb +36 -0
- data/lib/chef/knife/node_edit.rb +36 -0
- data/lib/chef/knife/node_from_file.rb +42 -0
- data/lib/chef/knife/node_list.rb +41 -0
- data/lib/chef/knife/node_run_list_add.rb +64 -0
- data/lib/chef/knife/node_run_list_remove.rb +45 -0
- data/lib/chef/knife/node_show.rb +46 -0
- data/lib/chef/knife/role_bulk_delete.rb +45 -0
- data/lib/chef/knife/role_create.rb +44 -0
- data/lib/chef/knife/role_delete.rb +36 -0
- data/lib/chef/knife/role_edit.rb +37 -0
- data/lib/chef/knife/role_from_file.rb +46 -0
- data/lib/chef/knife/role_list.rb +40 -0
- data/lib/chef/knife/role_show.rb +43 -0
- data/lib/chef/knife/search.rb +94 -0
- data/lib/chef/log.rb +39 -0
- data/lib/chef/mixin/check_helper.rb +31 -0
- data/lib/chef/mixin/checksum.rb +32 -0
- data/lib/chef/mixin/command.rb +390 -0
- data/lib/chef/mixin/convert_to_class_name.rb +57 -0
- data/lib/chef/mixin/create_path.rb +56 -0
- data/lib/chef/mixin/deep_merge.rb +33 -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 +58 -0
- data/lib/chef/mixin/language.rb +107 -0
- data/lib/chef/mixin/language_include_attribute.rb +56 -0
- data/lib/chef/mixin/language_include_recipe.rb +53 -0
- data/lib/chef/mixin/params_validate.rb +197 -0
- data/lib/chef/mixin/recipe_definition_dsl_core.rb +79 -0
- data/lib/chef/mixin/template.rb +94 -0
- data/lib/chef/nanite.rb +100 -0
- data/lib/chef/node.rb +463 -0
- data/lib/chef/node/attribute.rb +412 -0
- data/lib/chef/openid_registration.rb +181 -0
- data/lib/chef/platform.rb +268 -0
- data/lib/chef/provider.rb +101 -0
- data/lib/chef/provider/breakpoint.rb +36 -0
- data/lib/chef/provider/cron.rb +184 -0
- data/lib/chef/provider/deploy.rb +314 -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/erl_call.rb +72 -0
- data/lib/chef/provider/execute.rb +58 -0
- data/lib/chef/provider/file.rb +195 -0
- data/lib/chef/provider/git.rb +203 -0
- data/lib/chef/provider/group.rb +120 -0
- data/lib/chef/provider/group/dscl.rb +128 -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 +106 -0
- data/lib/chef/provider/ifconfig.rb +131 -0
- data/lib/chef/provider/link.rb +157 -0
- data/lib/chef/provider/mdadm.rb +88 -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/easy_install.rb +106 -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 +125 -0
- data/lib/chef/provider/package/yum.rb +175 -0
- data/lib/chef/provider/package/zypper.rb +132 -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 +33 -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 +156 -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 +114 -0
- data/lib/chef/provider/subversion.rb +156 -0
- data/lib/chef/provider/template.rb +175 -0
- data/lib/chef/provider/user.rb +170 -0
- data/lib/chef/provider/user/dscl.rb +280 -0
- data/lib/chef/provider/user/pw.rb +113 -0
- data/lib/chef/provider/user/useradd.rb +108 -0
- data/lib/chef/recipe.rb +105 -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/breakpoint.rb +35 -0
- data/lib/chef/resource/cron.rb +179 -0
- data/lib/chef/resource/csh.rb +33 -0
- data/lib/chef/resource/deploy.rb +359 -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/easy_install_package.rb +41 -0
- data/lib/chef/resource/erl_call.rb +83 -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/mdadm.rb +82 -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 +39 -0
- data/lib/chef/resource/scm.rb +137 -0
- data/lib/chef/resource/script.rb +51 -0
- data/lib/chef/resource/service.rb +134 -0
- data/lib/chef/resource/subversion.rb +34 -0
- data/lib/chef/resource/template.rb +60 -0
- data/lib/chef/resource/timestamped_deploy.rb +31 -0
- data/lib/chef/resource/user.rb +101 -0
- data/lib/chef/resource_collection.rb +212 -0
- data/lib/chef/resource_collection/stepable_iterator.rb +124 -0
- data/lib/chef/resource_definition.rb +67 -0
- data/lib/chef/rest.rb +298 -0
- data/lib/chef/role.rb +301 -0
- data/lib/chef/run_list.rb +164 -0
- data/lib/chef/runner.rb +130 -0
- data/lib/chef/search/query.rb +71 -0
- data/lib/chef/shef.rb +220 -0
- data/lib/chef/shef/ext.rb +297 -0
- data/lib/chef/shef/shef_session.rb +175 -0
- data/lib/chef/streaming_cookbook_uploader.rb +185 -0
- data/lib/chef/tasks/chef_repo.rake +245 -0
- data/lib/chef/util/file_edit.rb +125 -0
- data/lib/chef/util/fileedit.rb +121 -0
- data/lib/chef/webui_user.rb +231 -0
- metadata +398 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Author:: AJ Christensen (<aj@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/provider'
|
|
20
|
+
require 'chef/mixin/command'
|
|
21
|
+
require 'chef/resource/group'
|
|
22
|
+
require 'etc'
|
|
23
|
+
|
|
24
|
+
class Chef
|
|
25
|
+
class Provider
|
|
26
|
+
class Group < Chef::Provider
|
|
27
|
+
include Chef::Mixin::Command
|
|
28
|
+
attr_accessor :group_exists
|
|
29
|
+
|
|
30
|
+
def initialize(node, new_resource, collection=nil, definitions=nil, cookbook_loader=nil)
|
|
31
|
+
super(node, new_resource, collection, definitions, cookbook_loader)
|
|
32
|
+
@group_exists = true
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def load_current_resource
|
|
36
|
+
@current_resource = Chef::Resource::Group.new(@new_resource.name)
|
|
37
|
+
@current_resource.group_name(@new_resource.group_name)
|
|
38
|
+
|
|
39
|
+
group_info = nil
|
|
40
|
+
begin
|
|
41
|
+
group_info = Etc.getgrnam(@new_resource.group_name)
|
|
42
|
+
rescue ArgumentError => e
|
|
43
|
+
@group_exists = false
|
|
44
|
+
Chef::Log.debug("#{@new_resource}: group does not exist")
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
if group_info
|
|
48
|
+
@new_resource.gid(group_info.gid)
|
|
49
|
+
@current_resource.gid(group_info.gid)
|
|
50
|
+
@current_resource.members(group_info.mem)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
@current_resource
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Check to see if a group needs any changes
|
|
57
|
+
#
|
|
58
|
+
# ==== Returns
|
|
59
|
+
# <true>:: If a change is required
|
|
60
|
+
# <false>:: If a change is not required
|
|
61
|
+
def compare_group
|
|
62
|
+
return true if @new_resource.gid != @current_resource.gid
|
|
63
|
+
|
|
64
|
+
if(@new_resource.append)
|
|
65
|
+
@new_resource.members.each do |member|
|
|
66
|
+
next if @current_resource.members.include?(member)
|
|
67
|
+
return true
|
|
68
|
+
end
|
|
69
|
+
else
|
|
70
|
+
return true if @new_resource.members != @current_resource.members
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
return false
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def action_create
|
|
77
|
+
case @group_exists
|
|
78
|
+
when false
|
|
79
|
+
create_group
|
|
80
|
+
Chef::Log.info("Created #{@new_resource}")
|
|
81
|
+
@new_resource.updated = true
|
|
82
|
+
else
|
|
83
|
+
if compare_group
|
|
84
|
+
manage_group
|
|
85
|
+
Chef::Log.info("Altered #{@new_resource}")
|
|
86
|
+
@new_resource.updated = true
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def action_remove
|
|
92
|
+
if @group_exists
|
|
93
|
+
remove_group
|
|
94
|
+
@new_resource.updated = true
|
|
95
|
+
Chef::Log.info("Removed #{@new_resource}")
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def action_manage
|
|
100
|
+
if @group_exists && compare_group
|
|
101
|
+
manage_group
|
|
102
|
+
@new_resource.updated = true
|
|
103
|
+
Chef::Log.info("Managed #{@new_resource}")
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def action_modify
|
|
108
|
+
if @group_exists
|
|
109
|
+
if compare_group
|
|
110
|
+
manage_group
|
|
111
|
+
@new_resource.updated = true
|
|
112
|
+
Chef::Log.info("Modified #{@new_resource}")
|
|
113
|
+
end
|
|
114
|
+
else
|
|
115
|
+
raise Chef::Exceptions::Group, "Cannot modify #{@new_resource} - group does not exist!"
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Author:: Dreamcat4 (<dreamcat4@gmail.com>)
|
|
3
|
+
# Copyright:: Copyright (c) 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
|
+
class Chef
|
|
20
|
+
class Provider
|
|
21
|
+
class Group
|
|
22
|
+
class Dscl < Chef::Provider::Group
|
|
23
|
+
|
|
24
|
+
def dscl(*args)
|
|
25
|
+
host = "."
|
|
26
|
+
stdout_result = ""; stderr_result = ""; cmd = "dscl #{host} -#{args.join(' ')}"
|
|
27
|
+
status = popen4(cmd) do |pid, stdin, stdout, stderr|
|
|
28
|
+
stdout.each { |line| stdout_result << line }
|
|
29
|
+
stderr.each { |line| stderr_result << line }
|
|
30
|
+
end
|
|
31
|
+
return [cmd, status, stdout_result, stderr_result]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def safe_dscl(*args)
|
|
35
|
+
result = dscl(*args)
|
|
36
|
+
return "" if ( args.first =~ /^delete/ ) && ( result[1].exitstatus != 0 )
|
|
37
|
+
raise(Chef::Exceptions::Group,"dscl error: #{result.inspect}") unless result[1].exitstatus == 0
|
|
38
|
+
raise(Chef::Exceptions::Group,"dscl error: #{result.inspect}") if result[2] =~ /No such key: /
|
|
39
|
+
return result[2]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# This is handled in providers/group.rb by Etc.getgrnam()
|
|
43
|
+
# def group_exists?(group)
|
|
44
|
+
# groups = safe_dscl("list /Groups")
|
|
45
|
+
# !! ( groups =~ Regexp.new("\n#{group}\n") )
|
|
46
|
+
# end
|
|
47
|
+
|
|
48
|
+
# get a free GID greater than 200
|
|
49
|
+
def get_free_gid(search_limit=1000)
|
|
50
|
+
gid = nil; next_gid_guess = 200
|
|
51
|
+
groups_gids = safe_dscl("list /Groups gid")
|
|
52
|
+
while(next_gid_guess < search_limit + 200)
|
|
53
|
+
if groups_gids =~ Regexp.new("#{next_gid_guess}\n")
|
|
54
|
+
next_gid_guess += 1
|
|
55
|
+
else
|
|
56
|
+
gid = next_gid_guess
|
|
57
|
+
break
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
return gid || raise("gid not found. Exhausted. Searched #{search_limit} times")
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def gid_used?(gid)
|
|
64
|
+
return false unless gid
|
|
65
|
+
groups_gids = safe_dscl("list /Groups gid")
|
|
66
|
+
!! ( groups_gids =~ Regexp.new("#{gid}\n") )
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def set_gid
|
|
70
|
+
@new_resource.gid(get_free_gid) if [nil,""].include? @new_resource.gid
|
|
71
|
+
raise(Chef::Exceptions::Group,"gid is already in use") if gid_used?(@new_resource.gid)
|
|
72
|
+
safe_dscl("create /Groups/#{@new_resource.group_name} PrimaryGroupID #{@new_resource.gid}")
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def set_members
|
|
76
|
+
unless @new_resource.append
|
|
77
|
+
Chef::Log.debug("#{@new_resource}: removing group members #{@current_resource.members.join(' ')}") unless @current_resource.members.empty?
|
|
78
|
+
safe_dscl("create /Groups/#{@new_resource.group_name} GroupMembers") # clear guid list
|
|
79
|
+
safe_dscl("create /Groups/#{@new_resource.group_name} GroupMembership") # clear user list
|
|
80
|
+
end
|
|
81
|
+
Chef::Log.debug("#{@new_resource}: setting group members #{@new_resource.members.join(', ')}") unless @new_resource.members.empty?
|
|
82
|
+
safe_dscl("append /Groups/#{@new_resource.group_name} GroupMembership #{@new_resource.members.join(' ')}")
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def load_current_resource
|
|
86
|
+
super
|
|
87
|
+
raise Chef::Exceptions::Group, "Could not find binary /usr/bin/dscl for #{@new_resource}" unless ::File.exists?("/usr/bin/dscl")
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def create_group
|
|
91
|
+
manage_group(false)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def manage_group(manage=true)#
|
|
95
|
+
fields = []
|
|
96
|
+
if manage
|
|
97
|
+
[:group_name,:gid,:members].each do |field|
|
|
98
|
+
if @current_resource.send(field) != @new_resource.send(field)
|
|
99
|
+
fields << field if @new_resource.send(field)
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
else
|
|
103
|
+
# create
|
|
104
|
+
fields = [:group_name,:gid,:members]
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
fields.each do |field|
|
|
108
|
+
case field
|
|
109
|
+
when :group_name
|
|
110
|
+
safe_dscl("create /Groups/#{@new_resource.group_name}")
|
|
111
|
+
safe_dscl("create /Groups/#{@new_resource.group_name} Password '*'")
|
|
112
|
+
|
|
113
|
+
when :gid
|
|
114
|
+
set_gid
|
|
115
|
+
|
|
116
|
+
when :members
|
|
117
|
+
set_members
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def remove_group
|
|
123
|
+
safe_dscl("delete /Groups/#{@new_resource.group_name}")
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Author:: AJ Christensen (<aj@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/provider/group/groupadd'
|
|
20
|
+
|
|
21
|
+
class Chef
|
|
22
|
+
class Provider
|
|
23
|
+
class Group
|
|
24
|
+
class Gpasswd < Chef::Provider::Group::Groupadd
|
|
25
|
+
|
|
26
|
+
def load_current_resource
|
|
27
|
+
super
|
|
28
|
+
|
|
29
|
+
raise Chef::Exceptions::Group, "Could not find binary /usr/bin/gpasswd for #{@new_resource}" unless ::File.exists?("/usr/bin/gpasswd")
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def modify_group_members
|
|
33
|
+
unless @new_resource.members.empty?
|
|
34
|
+
if(@new_resource.append)
|
|
35
|
+
@new_resource.members.each do |member|
|
|
36
|
+
Chef::Log.debug("#{@new_resource}: appending member #{member} to group #{@new_resource.group_name}")
|
|
37
|
+
run_command(:command => "gpasswd -a #{member} #{@new_resource.group_name}")
|
|
38
|
+
end
|
|
39
|
+
else
|
|
40
|
+
Chef::Log.debug("#{@new_resource}: setting group members to #{@new_resource.members.join(', ')}")
|
|
41
|
+
run_command(:command => "gpasswd -M #{@new_resource.members.join(',')} #{@new_resource.group_name}")
|
|
42
|
+
end
|
|
43
|
+
else
|
|
44
|
+
Chef::Log.debug("#{@new_resource}: not changing group members, the group has no members")
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Author:: AJ Christensen (<aj@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
|
+
class Chef
|
|
20
|
+
class Provider
|
|
21
|
+
class Group
|
|
22
|
+
class Groupadd < Chef::Provider::Group
|
|
23
|
+
|
|
24
|
+
def load_current_resource
|
|
25
|
+
super
|
|
26
|
+
|
|
27
|
+
[ "/usr/sbin/groupadd",
|
|
28
|
+
"/usr/sbin/groupmod",
|
|
29
|
+
"/usr/sbin/groupdel" ].each do |required_binary|
|
|
30
|
+
raise Chef::Exceptions::Group, "Could not find binary #{required_binary} for #{@new_resource}" unless ::File.exists?(required_binary)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Create the group
|
|
35
|
+
def create_group
|
|
36
|
+
command = "groupadd"
|
|
37
|
+
command << set_options
|
|
38
|
+
run_command(:command => command)
|
|
39
|
+
modify_group_members
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Manage the group when it already exists
|
|
43
|
+
def manage_group
|
|
44
|
+
command = "groupmod"
|
|
45
|
+
command << set_options
|
|
46
|
+
run_command(:command => command)
|
|
47
|
+
modify_group_members
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Remove the group
|
|
51
|
+
def remove_group
|
|
52
|
+
run_command(:command => "groupdel #{@new_resource.group_name}")
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def modify_group_members
|
|
56
|
+
raise Chef::Exceptions::Group, "you must override modify_group_members in #{self.to_s}"
|
|
57
|
+
end
|
|
58
|
+
# Little bit of magic as per Adam's useradd provider to pull the assign the command line flags
|
|
59
|
+
#
|
|
60
|
+
# ==== Returns
|
|
61
|
+
# <string>:: A string containing the option and then the quoted value
|
|
62
|
+
def set_options
|
|
63
|
+
opts = ""
|
|
64
|
+
{ :gid => "-g" }.sort { |a,b| a[0] <=> b[0] }.each do |field, option|
|
|
65
|
+
if @current_resource.send(field) != @new_resource.send(field)
|
|
66
|
+
if @new_resource.send(field)
|
|
67
|
+
Chef::Log.debug("#{@new_resource}: setting #{field.to_s} to #{@new_resource.send(field)}")
|
|
68
|
+
opts << " #{option} '#{@new_resource.send(field)}'"
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
opts << " #{@new_resource.group_name}"
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Author:: Stephen Haynes (<sh@nomitor.com>)
|
|
3
|
+
# Copyright:: Copyright (c) 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
|
+
class Chef
|
|
20
|
+
class Provider
|
|
21
|
+
class Group
|
|
22
|
+
class Pw < Chef::Provider::Group
|
|
23
|
+
|
|
24
|
+
def load_current_resource
|
|
25
|
+
super
|
|
26
|
+
raise Chef::Exceptions::Group, "Could not find binary /usr/sbin/pw for #{@new_resource}" unless ::File.exists?("/usr/sbin/pw")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Create the group
|
|
30
|
+
def create_group
|
|
31
|
+
command = "pw groupadd"
|
|
32
|
+
command << set_options
|
|
33
|
+
command << set_members_option
|
|
34
|
+
run_command(:command => command)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Manage the group when it already exists
|
|
38
|
+
def manage_group
|
|
39
|
+
command = "pw groupmod"
|
|
40
|
+
command << set_options
|
|
41
|
+
command << set_members_option
|
|
42
|
+
run_command(:command => command)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Remove the group
|
|
46
|
+
def remove_group
|
|
47
|
+
run_command(:command => "pw groupdel #{@new_resource.group_name}")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Little bit of magic as per Adam's useradd provider to pull and assign the command line flags
|
|
51
|
+
#
|
|
52
|
+
# ==== Returns
|
|
53
|
+
# <string>:: A string containing the option and then the quoted value
|
|
54
|
+
def set_options
|
|
55
|
+
opts = " #{@new_resource.group_name}"
|
|
56
|
+
{ :gid => "-g" }.sort { |a,b| a[0] <=> b[0] }.each do |field, option|
|
|
57
|
+
if @current_resource.send(field) != @new_resource.send(field)
|
|
58
|
+
if @new_resource.send(field)
|
|
59
|
+
Chef::Log.debug("#{@new_resource}: setting #{field.to_s} to #{@new_resource.send(field)}")
|
|
60
|
+
opts << " #{option} '#{@new_resource.send(field)}'"
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
opts
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Set the membership option depending on the current resource states
|
|
68
|
+
def set_members_option
|
|
69
|
+
opt = ""
|
|
70
|
+
unless @new_resource.members.empty?
|
|
71
|
+
opt << " -M #{@new_resource.members.join(',')}"
|
|
72
|
+
Chef::Log.debug("#{@new_resource}: setting group members to #{@new_resource.members.join(', ')}")
|
|
73
|
+
else
|
|
74
|
+
# New member list is empty so we should delete any old group members
|
|
75
|
+
unless @current_resource.members.empty?
|
|
76
|
+
opt << " -d #{@current_resource.members.join(',')}"
|
|
77
|
+
Chef::Log.debug("#{@new_resource}: removing group members #{@current_resource.members.join(', ')}")
|
|
78
|
+
else
|
|
79
|
+
Chef::Log.debug("#{@new_resource}: not changing group members, the group has no members")
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
opt
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|