chef 12.17.44 → 12.18.31
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/README.md +3 -2
- data/Rakefile +9 -0
- data/VERSION +1 -1
- data/acceptance/Gemfile.lock +17 -17
- data/distro/common/html/knife_environment.html +4 -8
- data/distro/common/man/man1/knife-environment.1 +4 -16
- data/distro/powershell/chef/chef.psm1 +139 -24
- data/lib/chef/application.rb +5 -4
- data/lib/chef/application/windows_service_manager.rb +6 -4
- data/lib/chef/chef_fs/chef_fs_data_store.rb +1 -1
- data/lib/chef/chef_fs/command_line.rb +1 -1
- data/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb +8 -1
- data/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb +1 -1
- data/lib/chef/chef_fs/file_system/repository/nodes_dir.rb +1 -1
- data/lib/chef/cookbook/chefignore.rb +1 -1
- data/lib/chef/cookbook/cookbook_version_loader.rb +4 -4
- data/lib/chef/cookbook/metadata.rb +2 -2
- data/lib/chef/cookbook_loader.rb +1 -1
- data/lib/chef/data_collector.rb +24 -13
- data/lib/chef/data_collector/messages.rb +8 -6
- data/lib/chef/data_collector/messages/helpers.rb +1 -1
- data/lib/chef/deprecated.rb +30 -0
- data/lib/chef/dsl/platform_introspection.rb +2 -2
- data/lib/chef/encrypted_data_bag_item.rb +1 -1
- data/lib/chef/encrypted_data_bag_item/decryptor.rb +2 -2
- data/lib/chef/environment.rb +1 -1
- data/lib/chef/exceptions.rb +5 -5
- data/lib/chef/file_access_control/unix.rb +5 -5
- data/lib/chef/formatters/error_description.rb +1 -1
- data/lib/chef/http/basic_client.rb +1 -1
- data/lib/chef/http/json_input.rb +2 -2
- data/lib/chef/knife.rb +1 -1
- data/lib/chef/knife/cookbook_site_install.rb +1 -1
- data/lib/chef/knife/core/cookbook_scm_repo.rb +1 -1
- data/lib/chef/knife/core/ui.rb +1 -1
- data/lib/chef/mixin/command.rb +1 -0
- data/lib/chef/mixin/deep_merge.rb +1 -1
- data/lib/chef/mixin/shell_out.rb +58 -3
- data/lib/chef/mixin/which.rb +5 -9
- data/lib/chef/mixin/wide_string.rb +1 -1
- data/lib/chef/node.rb +1 -1
- data/lib/chef/node/attribute.rb +4 -5
- data/lib/chef/node_map.rb +18 -2
- data/lib/chef/platform/provider_handler_map.rb +2 -2
- data/lib/chef/platform/provider_mapping.rb +5 -0
- data/lib/chef/platform/resource_handler_map.rb +2 -2
- data/lib/chef/provider/env/windows.rb +1 -1
- data/lib/chef/provider/git.rb +1 -1
- data/lib/chef/provider/group.rb +41 -46
- data/lib/chef/provider/group/aix.rb +12 -19
- data/lib/chef/provider/group/dscl.rb +46 -43
- data/lib/chef/provider/group/gpasswd.rb +7 -7
- data/lib/chef/provider/group/groupadd.rb +29 -34
- data/lib/chef/provider/group/groupmod.rb +26 -31
- data/lib/chef/provider/group/pw.rb +28 -31
- data/lib/chef/provider/group/suse.rb +9 -9
- data/lib/chef/provider/group/usermod.rb +10 -11
- data/lib/chef/provider/group/windows.rb +18 -20
- data/lib/chef/provider/ifconfig.rb +52 -63
- data/lib/chef/provider/ifconfig/aix.rb +23 -28
- data/lib/chef/provider/ifconfig/debian.rb +23 -22
- data/lib/chef/provider/ifconfig/redhat.rb +12 -12
- data/lib/chef/provider/mount/mount.rb +1 -1
- data/lib/chef/provider/osx_profile.rb +4 -2
- data/lib/chef/provider/package.rb +16 -7
- data/lib/chef/provider/package/chocolatey.rb +3 -1
- data/lib/chef/provider/package/dnf.rb +183 -0
- data/lib/chef/provider/package/dnf/dnf_helper.py +91 -0
- data/lib/chef/provider/package/dnf/python_helper.rb +120 -0
- data/lib/chef/provider/package/dnf/version.rb +56 -0
- data/lib/chef/provider/package/easy_install.rb +1 -1
- data/lib/chef/provider/package/freebsd/base.rb +1 -1
- data/lib/chef/provider/package/freebsd/pkgng.rb +1 -1
- data/lib/chef/provider/package/powershell.rb +3 -3
- data/lib/chef/provider/package/windows.rb +1 -1
- data/lib/chef/provider/package/zypper.rb +1 -1
- data/lib/chef/provider/route.rb +186 -184
- data/lib/chef/provider/service/arch.rb +2 -2
- data/lib/chef/provider/service/freebsd.rb +1 -1
- data/lib/chef/provider/service/gentoo.rb +2 -2
- data/lib/chef/provider/service/insserv.rb +2 -2
- data/lib/chef/provider/service/macosx.rb +2 -2
- data/lib/chef/provider/service/openbsd.rb +1 -1
- data/lib/chef/provider/service/redhat.rb +2 -2
- data/lib/chef/provider/support/yum_repo.erb +10 -3
- data/lib/chef/provider/user.rb +17 -20
- data/lib/chef/provider/user/aix.rb +23 -24
- data/lib/chef/provider/user/dscl.rb +56 -53
- data/lib/chef/provider/user/linux.rb +13 -16
- data/lib/chef/provider/user/pw.rb +26 -30
- data/lib/chef/provider/user/solaris.rb +11 -12
- data/lib/chef/provider/user/useradd.rb +20 -22
- data/lib/chef/provider/user/windows.rb +19 -22
- data/lib/chef/provider_resolver.rb +4 -2
- data/lib/chef/providers.rb +1 -0
- data/lib/chef/resource.rb +7 -0
- data/lib/chef/resource/chocolatey_package.rb +1 -0
- data/lib/chef/resource/dnf_package.rb +64 -0
- data/lib/chef/resource/file/verification.rb +6 -4
- data/lib/chef/resource/yum_package.rb +18 -14
- data/lib/chef/resource/yum_repository.rb +1 -1
- data/lib/chef/resource_reporter.rb +11 -0
- data/lib/chef/resources.rb +1 -0
- data/lib/chef/scan_access_control.rb +4 -4
- data/lib/chef/util/dsc/resource_store.rb +1 -1
- data/lib/chef/version.rb +1 -1
- data/lib/chef/win32/memory.rb +1 -1
- data/lib/chef/win32/security.rb +2 -2
- data/lib/chef/win32/security/sid.rb +2 -2
- data/spec/functional/assets/yumrepo/chef_rpm-1.10-1.fc24.i686.rpm +0 -0
- data/spec/functional/assets/yumrepo/chef_rpm-1.10-1.fc24.src.rpm +0 -0
- data/spec/functional/assets/yumrepo/chef_rpm-1.10-1.fc24.x86_64.rpm +0 -0
- data/spec/functional/assets/yumrepo/chef_rpm-1.2-1.fc24.i686.rpm +0 -0
- data/spec/functional/assets/yumrepo/chef_rpm-1.2-1.fc24.src.rpm +0 -0
- data/spec/functional/assets/yumrepo/chef_rpm-1.2-1.fc24.x86_64.rpm +0 -0
- data/spec/functional/assets/yumrepo/repodata/313329137b55fd333b2dc66394a6661a2befa6cc535d8460d92a4a78a9c581f0-primary.sqlite.bz2 +0 -0
- data/spec/functional/assets/yumrepo/repodata/31ac4db5d5ac593728fcc26aef82b7b93c4cc4dbec843786b1845b939b658553-other.xml.gz +0 -0
- data/spec/functional/assets/yumrepo/repodata/4ac40fa3c6728c1401318e2e20a997436624e83dcf7a5f952b851ef422637773-filelists.sqlite.bz2 +0 -0
- data/spec/functional/assets/yumrepo/repodata/66391e53f0510b98b3f0b79f40ba1048026d9a1ef20905d9c40ba6f5411f3243-primary.xml.gz +0 -0
- data/spec/functional/assets/yumrepo/repodata/8b34697595fcc87928e12d24644dda9462c3857bd932861e28bc77ae1f31be16-filelists.xml.gz +0 -0
- data/spec/functional/assets/yumrepo/repodata/b97cca3fe14bcf06c52be4449b6108f7731239ff221111dcce8aada5467f60dc-other.sqlite.bz2 +0 -0
- data/spec/functional/assets/yumrepo/repodata/repomd.xml +55 -0
- data/spec/functional/resource/dnf_package_spec.rb +686 -0
- data/spec/functional/resource/dsc_script_spec.rb +1 -0
- data/spec/functional/resource/user/useradd_spec.rb +10 -1
- data/spec/integration/knife/chef_repo_path_spec.rb +2 -2
- data/spec/integration/recipes/recipe_dsl_spec.rb +3 -0
- data/spec/integration/recipes/resource_load_spec.rb +3 -3
- data/spec/spec_helper.rb +5 -3
- data/spec/support/lib/chef/provider/snakeoil.rb +1 -0
- data/spec/support/lib/chef/resource/cat.rb +1 -0
- data/spec/support/lib/chef/resource/one_two_three_four.rb +1 -0
- data/spec/support/lib/chef/resource/openldap_includer.rb +2 -0
- data/spec/support/lib/chef/resource/with_state.rb +2 -0
- data/spec/support/lib/chef/resource/zen_master.rb +1 -0
- data/spec/unit/cookbook/metadata_spec.rb +3 -3
- data/spec/unit/data_collector/messages/helpers_spec.rb +7 -0
- data/spec/unit/data_collector_spec.rb +56 -0
- data/spec/unit/decorator/lazy_spec.rb +1 -1
- data/spec/unit/environment_spec.rb +1 -1
- data/spec/unit/lwrp_spec.rb +3 -4
- data/spec/unit/node_spec.rb +23 -2
- data/spec/unit/platform_spec.rb +1 -0
- data/spec/unit/provider/group/dscl_spec.rb +29 -29
- data/spec/unit/provider/group/gpasswd_spec.rb +10 -10
- data/spec/unit/provider/group/groupadd_spec.rb +31 -30
- data/spec/unit/provider/group/groupmod_spec.rb +16 -16
- data/spec/unit/provider/group/pw_spec.rb +11 -11
- data/spec/unit/provider/group/suse_spec.rb +5 -5
- data/spec/unit/provider/group/usermod_spec.rb +15 -15
- data/spec/unit/provider/ifconfig/aix_spec.rb +14 -14
- data/spec/unit/provider/ifconfig/debian_spec.rb +10 -22
- data/spec/unit/provider/ifconfig/redhat_spec.rb +4 -4
- data/spec/unit/provider/ifconfig_spec.rb +18 -19
- data/spec/unit/provider/package/chocolatey_spec.rb +21 -21
- data/spec/unit/provider/package/msu_spec.rb +1 -1
- data/spec/unit/provider/route_spec.rb +21 -21
- data/spec/unit/provider/user/dscl_spec.rb +54 -57
- data/spec/unit/provider/user/linux_spec.rb +5 -5
- data/spec/unit/provider/user/pw_spec.rb +26 -22
- data/spec/unit/provider/user/windows_spec.rb +4 -4
- data/spec/unit/provider/user_spec.rb +19 -21
- data/spec/unit/provider_resolver_spec.rb +1 -0
- data/spec/unit/resource/chocolatey_package_spec.rb +12 -0
- data/spec/unit/resource/dnf_package_spec.rb +99 -0
- data/spec/unit/resource/remote_file_spec.rb +2 -2
- data/spec/unit/resource/yum_package_spec.rb +20 -0
- data/spec/unit/resource_reporter_spec.rb +24 -0
- data/spec/unit/resource_spec.rb +2 -0
- data/spec/unit/runner_spec.rb +1 -0
- data/tasks/bin/bundle-platform +1 -1
- data/tasks/gemfile_util.rb +2 -2
- data/tasks/templates/prerelease.md.erb +1 -10
- data/tasks/templates/release.md.erb +1 -9
- metadata +24 -5
- data/lib/chef/platform/handler_map.rb +0 -40
@@ -17,7 +17,6 @@
|
|
17
17
|
#
|
18
18
|
|
19
19
|
require "chef/provider/group/groupadd"
|
20
|
-
require "chef/mixin/shell_out"
|
21
20
|
|
22
21
|
class Chef
|
23
22
|
class Provider
|
@@ -33,48 +32,42 @@ class Chef
|
|
33
32
|
end
|
34
33
|
|
35
34
|
def create_group
|
36
|
-
|
37
|
-
command << set_options << " #{@new_resource.group_name}"
|
38
|
-
run_command(:command => command)
|
35
|
+
shell_out_compact!("mkgroup", set_options, new_resource.group_name)
|
39
36
|
modify_group_members
|
40
37
|
end
|
41
38
|
|
42
39
|
def manage_group
|
43
|
-
command = "chgroup"
|
44
40
|
options = set_options
|
45
|
-
#Usage: chgroup [-R load_module] "attr=value" ... group
|
46
41
|
if options.size > 0
|
47
|
-
|
48
|
-
run_command(:command => command)
|
42
|
+
shell_out_compact!("chgroup", options, new_resource.group_name)
|
49
43
|
end
|
50
44
|
modify_group_members
|
51
45
|
end
|
52
46
|
|
53
47
|
def remove_group
|
54
|
-
|
48
|
+
shell_out_compact!("rmgroup", new_resource.group_name)
|
55
49
|
end
|
56
50
|
|
57
51
|
def add_member(member)
|
58
|
-
|
52
|
+
shell_out_compact!("chgrpmem", "-m", "+", member, new_resource.group_name)
|
59
53
|
end
|
60
54
|
|
61
55
|
def set_members(members)
|
62
56
|
return if members.empty?
|
63
|
-
|
57
|
+
shell_out_compact!("chgrpmem", "-m", "=", members.join(","), new_resource.group_name)
|
64
58
|
end
|
65
59
|
|
66
60
|
def remove_member(member)
|
67
|
-
|
61
|
+
shell_out_compact!("chgrpmem", "-m", "-", member, new_resource.group_name)
|
68
62
|
end
|
69
63
|
|
70
64
|
def set_options
|
71
|
-
opts =
|
72
|
-
{ :
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
end
|
65
|
+
opts = []
|
66
|
+
{ gid: "id" }.sort { |a, b| a[0] <=> b[0] }.each do |field, option|
|
67
|
+
next unless current_resource.send(field) != new_resource.send(field)
|
68
|
+
if new_resource.send(field)
|
69
|
+
Chef::Log.debug("#{new_resource} setting #{field} to #{new_resource.send(field)}")
|
70
|
+
opts << "#{option}=#{new_resource.send(field)}"
|
78
71
|
end
|
79
72
|
end
|
80
73
|
opts
|
@@ -24,12 +24,15 @@ class Chef
|
|
24
24
|
provides :group, os: "darwin"
|
25
25
|
|
26
26
|
def dscl(*args)
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
argdup = args.dup
|
28
|
+
cmd = argdup.shift
|
29
|
+
shellcmd = [ "dscl", ".", "-#{cmd}", argdup ]
|
30
|
+
status = shell_out_compact(shellcmd)
|
31
|
+
stdout_result = ""
|
32
|
+
stderr_result = ""
|
30
33
|
status.stdout.each_line { |line| stdout_result << line }
|
31
34
|
status.stderr.each_line { |line| stderr_result << line }
|
32
|
-
|
35
|
+
[shellcmd.flatten.compact.join(" "), status, stdout_result, stderr_result]
|
33
36
|
end
|
34
37
|
|
35
38
|
def safe_dscl(*args)
|
@@ -37,18 +40,18 @@ class Chef
|
|
37
40
|
return "" if ( args.first =~ /^delete/ ) && ( result[1].exitstatus != 0 )
|
38
41
|
raise(Chef::Exceptions::Group, "dscl error: #{result.inspect}") unless result[1].exitstatus == 0
|
39
42
|
raise(Chef::Exceptions::Group, "dscl error: #{result.inspect}") if result[2] =~ /No such key: /
|
40
|
-
|
43
|
+
result[2]
|
41
44
|
end
|
42
45
|
|
43
46
|
def load_current_resource
|
44
|
-
@current_resource = Chef::Resource::Group.new(
|
45
|
-
|
47
|
+
@current_resource = Chef::Resource::Group.new(new_resource.name)
|
48
|
+
current_resource.group_name(new_resource.group_name)
|
46
49
|
group_info = nil
|
47
50
|
begin
|
48
|
-
group_info = safe_dscl("read /Groups/#{
|
51
|
+
group_info = safe_dscl("read", "/Groups/#{new_resource.group_name}")
|
49
52
|
rescue Chef::Exceptions::Group
|
50
53
|
@group_exists = false
|
51
|
-
Chef::Log.debug("#{
|
54
|
+
Chef::Log.debug("#{new_resource} group does not exist")
|
52
55
|
end
|
53
56
|
|
54
57
|
if group_info
|
@@ -57,21 +60,21 @@ class Chef
|
|
57
60
|
val.strip! if val
|
58
61
|
case key.downcase
|
59
62
|
when "primarygroupid"
|
60
|
-
|
61
|
-
|
63
|
+
new_resource.gid(val) unless new_resource.gid
|
64
|
+
current_resource.gid(val)
|
62
65
|
when "groupmembership"
|
63
|
-
|
66
|
+
current_resource.members(val.split(" "))
|
64
67
|
end
|
65
68
|
end
|
66
69
|
end
|
67
70
|
|
68
|
-
|
71
|
+
current_resource
|
69
72
|
end
|
70
73
|
|
71
74
|
# get a free GID greater than 200
|
72
75
|
def get_free_gid(search_limit = 1000)
|
73
76
|
gid = nil; next_gid_guess = 200
|
74
|
-
groups_gids = safe_dscl("list /Groups gid")
|
77
|
+
groups_gids = safe_dscl("list", "/Groups", "gid")
|
75
78
|
while next_gid_guess < search_limit + 200
|
76
79
|
if groups_gids =~ Regexp.new("#{Regexp.escape(next_gid_guess.to_s)}\n")
|
77
80
|
next_gid_guess += 1
|
@@ -80,51 +83,51 @@ class Chef
|
|
80
83
|
break
|
81
84
|
end
|
82
85
|
end
|
83
|
-
|
86
|
+
gid || raise("gid not found. Exhausted. Searched #{search_limit} times")
|
84
87
|
end
|
85
88
|
|
86
89
|
def gid_used?(gid)
|
87
90
|
return false unless gid
|
88
|
-
groups_gids = safe_dscl("list /Groups gid")
|
89
|
-
!!
|
91
|
+
groups_gids = safe_dscl("list", "/Groups", "gid")
|
92
|
+
!!( groups_gids =~ Regexp.new("#{Regexp.escape(gid.to_s)}\n") )
|
90
93
|
end
|
91
94
|
|
92
95
|
def set_gid
|
93
|
-
|
94
|
-
raise(Chef::Exceptions::Group, "gid is already in use") if gid_used?(
|
95
|
-
safe_dscl("create /Groups/#{
|
96
|
+
new_resource.gid(get_free_gid) if [nil, ""].include? new_resource.gid
|
97
|
+
raise(Chef::Exceptions::Group, "gid is already in use") if gid_used?(new_resource.gid)
|
98
|
+
safe_dscl("create", "/Groups/#{new_resource.group_name}", "PrimaryGroupID", new_resource.gid)
|
96
99
|
end
|
97
100
|
|
98
101
|
def set_members
|
99
102
|
# First reset the memberships if the append is not set
|
100
|
-
unless
|
101
|
-
Chef::Log.debug("#{
|
102
|
-
safe_dscl("create /Groups/#{
|
103
|
-
safe_dscl("create /Groups/#{
|
104
|
-
|
103
|
+
unless new_resource.append
|
104
|
+
Chef::Log.debug("#{new_resource} removing group members #{current_resource.members.join(' ')}") unless current_resource.members.empty?
|
105
|
+
safe_dscl("create", "/Groups/#{new_resource.group_name}", "GroupMembers", "") # clear guid list
|
106
|
+
safe_dscl("create", "/Groups/#{new_resource.group_name}", "GroupMembership", "") # clear user list
|
107
|
+
current_resource.members([ ])
|
105
108
|
end
|
106
109
|
|
107
110
|
# Add any members that need to be added
|
108
|
-
if
|
111
|
+
if new_resource.members && !new_resource.members.empty?
|
109
112
|
members_to_be_added = [ ]
|
110
|
-
|
111
|
-
members_to_be_added << member
|
113
|
+
new_resource.members.each do |member|
|
114
|
+
members_to_be_added << member unless current_resource.members.include?(member)
|
112
115
|
end
|
113
116
|
unless members_to_be_added.empty?
|
114
|
-
Chef::Log.debug("#{
|
115
|
-
safe_dscl("append /Groups/#{
|
117
|
+
Chef::Log.debug("#{new_resource} setting group members #{members_to_be_added.join(', ')}")
|
118
|
+
safe_dscl("append", "/Groups/#{new_resource.group_name}", "GroupMembership", *members_to_be_added)
|
116
119
|
end
|
117
120
|
end
|
118
121
|
|
119
122
|
# Remove any members that need to be removed
|
120
|
-
if
|
123
|
+
if new_resource.excluded_members && !new_resource.excluded_members.empty?
|
121
124
|
members_to_be_removed = [ ]
|
122
|
-
|
123
|
-
members_to_be_removed << member if
|
125
|
+
new_resource.excluded_members.each do |member|
|
126
|
+
members_to_be_removed << member if current_resource.members.include?(member)
|
124
127
|
end
|
125
128
|
unless members_to_be_removed.empty?
|
126
|
-
Chef::Log.debug("#{
|
127
|
-
safe_dscl("delete /Groups/#{
|
129
|
+
Chef::Log.debug("#{new_resource} removing group members #{members_to_be_removed.join(', ')}")
|
130
|
+
safe_dscl("delete", "/Groups/#{new_resource.group_name}", "GroupMembership", *members_to_be_removed)
|
128
131
|
end
|
129
132
|
end
|
130
133
|
end
|
@@ -132,8 +135,8 @@ class Chef
|
|
132
135
|
def define_resource_requirements
|
133
136
|
super
|
134
137
|
requirements.assert(:all_actions) do |a|
|
135
|
-
a.assertion { ::File.
|
136
|
-
a.failure_message Chef::Exceptions::Group, "Could not find binary /usr/bin/dscl for #{
|
138
|
+
a.assertion { ::File.exist?("/usr/bin/dscl") }
|
139
|
+
a.failure_message Chef::Exceptions::Group, "Could not find binary /usr/bin/dscl for #{new_resource.name}"
|
137
140
|
# No whyrun alternative: this component should be available in the base install of any given system that uses it
|
138
141
|
end
|
139
142
|
end
|
@@ -145,24 +148,24 @@ class Chef
|
|
145
148
|
end
|
146
149
|
|
147
150
|
def manage_group
|
148
|
-
if
|
151
|
+
if new_resource.group_name && (current_resource.group_name != new_resource.group_name)
|
149
152
|
dscl_create_group
|
150
153
|
end
|
151
|
-
if
|
154
|
+
if new_resource.gid && (current_resource.gid != new_resource.gid)
|
152
155
|
set_gid
|
153
156
|
end
|
154
|
-
if
|
157
|
+
if new_resource.members || new_resource.excluded_members
|
155
158
|
set_members
|
156
159
|
end
|
157
160
|
end
|
158
161
|
|
159
162
|
def dscl_create_group
|
160
|
-
safe_dscl("create /Groups/#{
|
161
|
-
safe_dscl("create /Groups/#{
|
163
|
+
safe_dscl("create", "/Groups/#{new_resource.group_name}")
|
164
|
+
safe_dscl("create", "/Groups/#{new_resource.group_name}", "Password", "*")
|
162
165
|
end
|
163
166
|
|
164
167
|
def remove_group
|
165
|
-
safe_dscl("delete /Groups/#{
|
168
|
+
safe_dscl("delete", "/Groups/#{new_resource.group_name}")
|
166
169
|
end
|
167
170
|
end
|
168
171
|
end
|
@@ -31,26 +31,26 @@ class Chef
|
|
31
31
|
def define_resource_requirements
|
32
32
|
super
|
33
33
|
requirements.assert(:all_actions) do |a|
|
34
|
-
a.assertion { ::File.
|
35
|
-
a.failure_message Chef::Exceptions::Group, "Could not find binary /usr/bin/gpasswd for #{
|
34
|
+
a.assertion { ::File.exist?("/usr/bin/gpasswd") }
|
35
|
+
a.failure_message Chef::Exceptions::Group, "Could not find binary /usr/bin/gpasswd for #{new_resource}"
|
36
36
|
# No whyrun alternative: this component should be available in the base install of any given system that uses it
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
def set_members(members)
|
41
|
-
|
42
|
-
|
41
|
+
if members.empty?
|
42
|
+
shell_out_compact!("gpasswd", "-M", "", new_resource.group_name)
|
43
43
|
else
|
44
|
-
|
44
|
+
shell_out_compact!("gpasswd", "-M", members.join(","), new_resource.group_name)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
def add_member(member)
|
49
|
-
|
49
|
+
shell_out_compact!("gpasswd", "-a", member, new_resource.group_name)
|
50
50
|
end
|
51
51
|
|
52
52
|
def remove_member(member)
|
53
|
-
|
53
|
+
shell_out_compact!("gpasswd", "-d", member, new_resource.group_name)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
@@ -35,8 +35,8 @@ class Chef
|
|
35
35
|
super
|
36
36
|
required_binaries.each do |required_binary|
|
37
37
|
requirements.assert(:all_actions) do |a|
|
38
|
-
a.assertion { ::File.
|
39
|
-
a.failure_message Chef::Exceptions::Group, "Could not find binary #{required_binary} for #{
|
38
|
+
a.assertion { ::File.exist?(required_binary) }
|
39
|
+
a.failure_message Chef::Exceptions::Group, "Could not find binary #{required_binary} for #{new_resource}"
|
40
40
|
# No whyrun alternative: this component should be available in the base install of any given system that uses it
|
41
41
|
end
|
42
42
|
end
|
@@ -44,54 +44,49 @@ class Chef
|
|
44
44
|
|
45
45
|
# Create the group
|
46
46
|
def create_group
|
47
|
-
|
48
|
-
command << set_options
|
49
|
-
command << groupadd_options
|
50
|
-
run_command(:command => command)
|
47
|
+
shell_out_compact!("groupadd", set_options, groupadd_options)
|
51
48
|
modify_group_members
|
52
49
|
end
|
53
50
|
|
54
51
|
# Manage the group when it already exists
|
55
52
|
def manage_group
|
56
|
-
|
57
|
-
command << set_options
|
58
|
-
run_command(:command => command)
|
53
|
+
shell_out_compact!("groupmod", set_options)
|
59
54
|
modify_group_members
|
60
55
|
end
|
61
56
|
|
62
57
|
# Remove the group
|
63
58
|
def remove_group
|
64
|
-
|
59
|
+
shell_out_compact!("groupdel", new_resource.group_name)
|
65
60
|
end
|
66
61
|
|
67
62
|
def modify_group_members
|
68
|
-
if
|
69
|
-
if
|
63
|
+
if new_resource.append
|
64
|
+
if new_resource.members && !new_resource.members.empty?
|
70
65
|
members_to_be_added = [ ]
|
71
|
-
|
72
|
-
members_to_be_added << member
|
66
|
+
new_resource.members.each do |member|
|
67
|
+
members_to_be_added << member unless current_resource.members.include?(member)
|
73
68
|
end
|
74
69
|
members_to_be_added.each do |member|
|
75
|
-
Chef::Log.debug("#{
|
70
|
+
Chef::Log.debug("#{new_resource} appending member #{member} to group #{new_resource.group_name}")
|
76
71
|
add_member(member)
|
77
72
|
end
|
78
73
|
end
|
79
74
|
|
80
|
-
if
|
75
|
+
if new_resource.excluded_members && !new_resource.excluded_members.empty?
|
81
76
|
members_to_be_removed = [ ]
|
82
|
-
|
83
|
-
members_to_be_removed << member if
|
77
|
+
new_resource.excluded_members.each do |member|
|
78
|
+
members_to_be_removed << member if current_resource.members.include?(member)
|
84
79
|
end
|
85
80
|
|
86
81
|
members_to_be_removed.each do |member|
|
87
|
-
Chef::Log.debug("#{
|
82
|
+
Chef::Log.debug("#{new_resource} removing member #{member} from group #{new_resource.group_name}")
|
88
83
|
remove_member(member)
|
89
84
|
end
|
90
85
|
end
|
91
86
|
else
|
92
|
-
members_description =
|
93
|
-
Chef::Log.debug("#{
|
94
|
-
set_members(
|
87
|
+
members_description = new_resource.members.empty? ? "none" : new_resource.members.join(", ")
|
88
|
+
Chef::Log.debug("#{new_resource} setting group members to: #{members_description}")
|
89
|
+
set_members(new_resource.members)
|
95
90
|
end
|
96
91
|
end
|
97
92
|
|
@@ -112,23 +107,23 @@ class Chef
|
|
112
107
|
# ==== Returns
|
113
108
|
# <string>:: A string containing the option and then the quoted value
|
114
109
|
def set_options
|
115
|
-
opts =
|
116
|
-
{ :
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
end
|
110
|
+
opts = []
|
111
|
+
{ gid: "-g" }.sort { |a, b| a[0] <=> b[0] }.each do |field, option|
|
112
|
+
next unless current_resource.send(field) != new_resource.send(field)
|
113
|
+
next unless new_resource.send(field)
|
114
|
+
opts << option
|
115
|
+
opts << new_resource.send(field)
|
116
|
+
Chef::Log.debug("#{new_resource} set #{field} to #{new_resource.send(field)}")
|
123
117
|
end
|
124
|
-
opts <<
|
118
|
+
opts << new_resource.group_name
|
119
|
+
opts
|
125
120
|
end
|
126
121
|
|
127
122
|
def groupadd_options
|
128
|
-
opts =
|
123
|
+
opts = []
|
129
124
|
# Solaris doesn't support system groups.
|
130
|
-
opts << "
|
131
|
-
opts << "
|
125
|
+
opts << "-r" if new_resource.system && !node.platform?("solaris2")
|
126
|
+
opts << "-o" if new_resource.non_unique
|
132
127
|
opts
|
133
128
|
end
|
134
129
|
|
@@ -26,28 +26,26 @@ class Chef
|
|
26
26
|
def load_current_resource
|
27
27
|
super
|
28
28
|
%w{group user}.each do |binary|
|
29
|
-
raise Chef::Exceptions::Group, "Could not find binary /usr/sbin/#{binary} for #{
|
29
|
+
raise Chef::Exceptions::Group, "Could not find binary /usr/sbin/#{binary} for #{new_resource}" unless ::File.exist?("/usr/sbin/#{binary}")
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
# Create the group
|
34
34
|
def create_group
|
35
|
-
|
36
|
-
command << set_options
|
37
|
-
shell_out!(command)
|
35
|
+
shell_out_compact!("group", "add", set_options)
|
38
36
|
|
39
|
-
add_group_members(
|
37
|
+
add_group_members(new_resource.members)
|
40
38
|
end
|
41
39
|
|
42
40
|
# Manage the group when it already exists
|
43
41
|
def manage_group
|
44
|
-
if
|
42
|
+
if new_resource.append
|
45
43
|
members_to_be_added = [ ]
|
46
|
-
if
|
44
|
+
if new_resource.excluded_members && !new_resource.excluded_members.empty?
|
47
45
|
# First find out if any member needs to be removed
|
48
46
|
members_to_be_removed = [ ]
|
49
|
-
|
50
|
-
members_to_be_removed << member if
|
47
|
+
new_resource.excluded_members.each do |member|
|
48
|
+
members_to_be_removed << member if current_resource.members.include?(member)
|
51
49
|
end
|
52
50
|
|
53
51
|
unless members_to_be_removed.empty?
|
@@ -56,39 +54,39 @@ class Chef
|
|
56
54
|
|
57
55
|
# Capture the members we need to add in
|
58
56
|
# members_to_be_added to be added later on.
|
59
|
-
|
57
|
+
current_resource.members.each do |member|
|
60
58
|
members_to_be_added << member unless members_to_be_removed.include?(member)
|
61
59
|
end
|
62
60
|
end
|
63
61
|
end
|
64
62
|
|
65
|
-
if
|
66
|
-
|
67
|
-
members_to_be_added << member
|
63
|
+
if new_resource.members && !new_resource.members.empty?
|
64
|
+
new_resource.members.each do |member|
|
65
|
+
members_to_be_added << member unless current_resource.members.include?(member)
|
68
66
|
end
|
69
67
|
end
|
70
68
|
|
71
|
-
Chef::Log.debug("#{
|
69
|
+
Chef::Log.debug("#{new_resource} not changing group members, the group has no members to add") if members_to_be_added.empty?
|
72
70
|
|
73
71
|
add_group_members(members_to_be_added)
|
74
72
|
else
|
75
73
|
# We are resetting the members of a group so use the same trick
|
76
74
|
reset_group_membership
|
77
|
-
Chef::Log.debug("#{
|
78
|
-
add_group_members(
|
75
|
+
Chef::Log.debug("#{new_resource} setting group members to: none") if new_resource.members.empty?
|
76
|
+
add_group_members(new_resource.members)
|
79
77
|
end
|
80
78
|
end
|
81
79
|
|
82
80
|
# Remove the group
|
83
81
|
def remove_group
|
84
|
-
|
82
|
+
shell_out_compact!("group", "del", new_resource.group_name)
|
85
83
|
end
|
86
84
|
|
87
85
|
# Adds a list of usernames to the group using `user mod`
|
88
86
|
def add_group_members(members)
|
89
|
-
Chef::Log.debug("#{
|
87
|
+
Chef::Log.debug("#{new_resource} adding members #{members.join(', ')}") unless members.empty?
|
90
88
|
members.each do |user|
|
91
|
-
|
89
|
+
shell_out_compact!("user", "mod", "-G", new_resource.group_name, user)
|
92
90
|
end
|
93
91
|
end
|
94
92
|
|
@@ -96,15 +94,11 @@ class Chef
|
|
96
94
|
# "<name>_bak", create a new group with the same GID and
|
97
95
|
# "<name>", then set correct members on that group
|
98
96
|
def reset_group_membership
|
99
|
-
|
100
|
-
shell_out!(rename)
|
97
|
+
shell_out_compact!("group", "mod", "-n", "#{new_resource.group_name}_bak", new_resource.group_name)
|
101
98
|
|
102
|
-
|
103
|
-
create << set_options(:overwrite_gid => true)
|
104
|
-
shell_out!(create)
|
99
|
+
shell_out_compact!("group", "add", set_options(overwrite_gid: true))
|
105
100
|
|
106
|
-
|
107
|
-
shell_out!(remove)
|
101
|
+
shell_out_compact!("group", "del", "#{new_resource.group_name}_bak")
|
108
102
|
end
|
109
103
|
|
110
104
|
# Little bit of magic as per Adam's useradd provider to pull and assign the command line flags
|
@@ -112,14 +106,15 @@ class Chef
|
|
112
106
|
# ==== Returns
|
113
107
|
# <string>:: A string containing the option and then the quoted value
|
114
108
|
def set_options(overwrite_gid = false)
|
115
|
-
opts =
|
116
|
-
if overwrite_gid ||
|
117
|
-
opts << "
|
109
|
+
opts = []
|
110
|
+
if overwrite_gid || new_resource.gid && (current_resource.gid != new_resource.gid)
|
111
|
+
opts << "-g"
|
112
|
+
opts << new_resource.gid
|
118
113
|
end
|
119
114
|
if overwrite_gid
|
120
|
-
opts << "
|
115
|
+
opts << "-o"
|
121
116
|
end
|
122
|
-
opts <<
|
117
|
+
opts << new_resource.group_name
|
123
118
|
opts
|
124
119
|
end
|
125
120
|
end
|