74
74
- Specifies the encrypted string for the password to create or change the password.
75
75
- Can be used when I(state=present) or I(state=modify).
76
76
type: str
77
+ load_module:
78
+ description:
79
+ - Specifies the location where the operations need to be performed on the user.
80
+ - C(files) creates/updates/deletes the user present in the Local machine.
81
+ - C(LDAP) creates/updates the user present in the LDAP server.
82
+ type: str
83
+ default: 'files'
84
+ choices: [files, LDAP]
77
85
notes:
78
86
- You can refer to the IBM documentation for additional information on the commands used at
79
87
U(https://www.ibm.com/support/knowledgecenter/ssw_aix_72/c_commands/chuser.html),
@@ -134,7 +142,7 @@ def get_chuser_command(module):
134
142
return None
135
143
136
144
# 'user_attrs' contains the key=value pairs that are _currently_ set in AIX
137
- lsuser_cmd = "lsuser -C %s" % module .params ['name' ]
145
+ lsuser_cmd = "lsuser -R %s - C %s" % ( module .params ['load_module' ], module . params [ ' name' ])
138
146
rc , stdout , stderr = module .run_command (lsuser_cmd )
139
147
if rc != 0 :
140
148
msg = "\n Failed to validate attributes for the user: %s" % module .params ['name' ]
@@ -143,23 +151,23 @@ def get_chuser_command(module):
143
151
values = stdout .splitlines ()[1 ].split (':' )
144
152
user_attrs = dict (zip (keys , values ))
145
153
154
+ # Adding the load module to the command so that the correct user's attributes are changed.
155
+ load_module_opts = "-R %s " % module .params ['load_module' ]
156
+
146
157
# Now loop over every key-value in attributes
147
158
opts = ""
148
159
cmd = ""
149
160
load_module_opts = None
150
161
for attr , val in attributes .items ():
151
- if attr == 'load_module' :
152
- load_module_opts = "-R %s " % val
153
- else :
154
- pattern = re .compile (r'(yes|true|always|no|false|never)' , re .IGNORECASE )
155
- if val in [True , False ] or re .match (pattern , str (val )):
156
- val = str (val ).lower ()
157
- # For idempotency, we compare what Anisble whats the value to be
158
- # compared to what is already set
159
- # Only add attr=val to the opts list they're different. No reason to
160
- # if the values are identical!
161
- if user_attrs [attr ] != val :
162
- opts += "%s=\" %s\" " % (attr , val )
162
+ pattern = re .compile (r'(yes|true|always|no|false|never)' , re .IGNORECASE )
163
+ if val in [True , False ] or re .match (pattern , str (val )):
164
+ val = str (val ).lower ()
165
+ # For idempotency, we compare what Anisble whats the value to be
166
+ # compared to what is already set
167
+ # Only add attr=val to the opts list they're different. No reason to
168
+ # if the values are identical!
169
+ if user_attrs [attr ] != val :
170
+ opts += "%s=\" %s\" " % (attr , val )
163
171
164
172
if load_module_opts is not None :
165
173
opts = load_module_opts + opts
@@ -232,12 +240,12 @@ def create_user(module):
232
240
load_module_opts = None
233
241
msg = ""
234
242
243
+ # Adding the load module to the command so that the user is created at the right location.
244
+ load_module_opts = "-R %s " % module .params ['load_module' ]
245
+
235
246
if attributes is not None :
236
247
for attr , val in attributes .items ():
237
- if attr == 'load_module' :
238
- load_module_opts = "-R %s " % val
239
- else :
240
- opts += "%s=\" %s\" " % (attr , val )
248
+ opts += "%s=\" %s\" " % (attr , val )
241
249
if load_module_opts is not None :
242
250
opts = load_module_opts + opts
243
251
cmd = "mkuser %s %s" % (opts , module .params ['name' ])
@@ -294,8 +302,12 @@ def user_exists(module):
294
302
True if the user exists
295
303
False if the user does not exist
296
304
'''
297
- cmd = ["lsuser" ]
298
- cmd .append (module .params ['name' ])
305
+ cmd = "lsuser "
306
+
307
+ # Adding the load module to the command so that the user's existence is checked at the right location.
308
+ load_module_opts = "-R %s" % module .params ['load_module' ]
309
+ cmd += load_module_opts
310
+ cmd += " %s" % module .params ['name' ]
299
311
300
312
rc , out , err = module .run_command (cmd )
301
313
if rc == 0 :
@@ -325,6 +337,7 @@ def change_password(module):
325
337
else :
326
338
cmd = "echo \' {user}:{password}\' | chpasswd -e -c" .format (user = name , password = passwd )
327
339
340
+ cmd += " -R %s" % module .params ['load_module' ]
328
341
pass_rc , pass_out , pass_err = module .run_command (cmd , use_unsafe_shell = True )
329
342
if pass_rc != 0 :
330
343
msg = "\n Failed to set password for the user: %s" % module .params ['name' ]
@@ -344,6 +357,7 @@ def main():
344
357
remove_homedir = dict (type = 'bool' , default = True , no_log = False ),
345
358
change_passwd_on_login = dict (type = 'bool' , default = False , no_log = False ),
346
359
password = dict (type = 'str' , no_log = True ),
360
+ load_module = dict (type = 'str' , default = 'files' , choices = ['files' , 'LDAP' ]),
347
361
),
348
362
supports_check_mode = False
349
363
)
0 commit comments