17
17
value . is_a? Integer
18
18
end
19
19
20
- optional_commands :localadd => "lgroupadd" , :localdelete => "lgroupdel" , :localmodify => "lgroupmod"
21
-
22
- has_feature :manages_local_users_and_groups , :manages_members if Puppet . features . libuser?
23
-
24
- options :members , :flag => '-M' , :method => :mem
20
+ optional_commands :localadd => "lgroupadd" , :localdelete => "lgroupdel" , :localmodify => "lgroupmod" , :purgemember => "usermod"
21
+
22
+ has_feature :manages_local_users_and_groups if Puppet . features . libuser?
23
+ has_feature :manages_members if Puppet . features . libuser? ||
24
+ ( Puppet . runtime [ :facter ] . value ( 'os.name' ) == "Fedora" &&
25
+ Puppet . runtime [ :facter ] . value ( 'os.release.major' ) . to_i >= 40 )
26
+
27
+ # Libuser's modify command 'lgroupmod' requires '-M' flag for member additions.
28
+ # 'groupmod' command requires the '-aU' flags for it.
29
+ if Puppet . features . libuser?
30
+ options :members , :flag => '-M' , :method => :mem
31
+ else
32
+ options :members , :flag => '-aU' , :method => :mem
33
+ end
25
34
26
35
def exists?
27
36
return !!localgid if @resource . forcelocal?
@@ -63,7 +72,8 @@ def create
63
72
end
64
73
65
74
def addcmd
66
- if @resource . forcelocal?
75
+ # The localadd command (lgroupadd) must only be called when libuser is supported.
76
+ if Puppet . features . libuser? && @resource . forcelocal?
67
77
cmd = [ command ( :localadd ) ]
68
78
@custom_environment = Puppet ::Util ::Libuser . getenv
69
79
else
@@ -91,7 +101,8 @@ def validate_members(members)
91
101
end
92
102
93
103
def modifycmd ( param , value )
94
- if @resource . forcelocal? || @resource [ :members ]
104
+ # The localmodify command (lgroupmod) must only be called when libuser is supported.
105
+ if Puppet . features . libuser? && ( @resource . forcelocal? || @resource [ :members ] )
95
106
cmd = [ command ( :localmodify ) ]
96
107
@custom_environment = Puppet ::Util ::Libuser . getenv
97
108
else
@@ -114,7 +125,8 @@ def modifycmd(param, value)
114
125
end
115
126
116
127
def deletecmd
117
- if @resource . forcelocal?
128
+ # The localdelete command (lgroupdel) must only be called when libuser is supported.
129
+ if Puppet . features . libuser? && @resource . forcelocal?
118
130
@custom_environment = Puppet ::Util ::Libuser . getenv
119
131
[ command ( :localdelete ) , @resource [ :name ] ]
120
132
else
@@ -133,7 +145,16 @@ def members_to_s(current)
133
145
end
134
146
135
147
def purge_members
136
- localmodify ( '-m' , members_to_s ( members ) , @resource . name )
148
+ # The groupadd provider doesn't have the ability currently to remove members from a group, libuser does.
149
+ # Use libuser's lgroupmod command to achieve purging members if libuser is supported.
150
+ # Otherwise use the 'usermod' command.
151
+ if Puppet . features . libuser?
152
+ localmodify ( '-m' , members_to_s ( members ) , @resource . name )
153
+ else
154
+ members . each do |member |
155
+ purgemember ( '-rG' , @resource . name , member )
156
+ end
157
+ end
137
158
end
138
159
139
160
private
0 commit comments