@@ -238,9 +238,9 @@ def __init__(self):
238
238
'privacy_password' , 'privacy_protocol' ]
239
239
used_unsupported_rest_properties = [x for x in unsupported_rest_properties if x in self .parameters ]
240
240
self .use_rest , error = self .restApi .is_rest (used_unsupported_rest_properties )
241
- if self . restApi . is_rest () :
242
- self .use_rest = True
243
- else :
241
+ if error is not None :
242
+ self .module . fail_json ( msg = error )
243
+ if not self . use_rest :
244
244
if not HAS_NETAPP_LIB :
245
245
self .module .fail_json (msg = "the python NetApp-Lib module is required" )
246
246
else :
@@ -272,7 +272,7 @@ def get_user_details_rest(self, name, uuid):
272
272
return_value = {
273
273
'lock_user' : message ['locked' ],
274
274
'role_name' : message ['role' ]['name' ],
275
- 'applications' : message ['applications' ]
275
+ 'applications' : [ app [ 'application' ] for app in message ['applications' ] ]
276
276
}
277
277
return return_value
278
278
@@ -463,6 +463,13 @@ def delete_user(self, application):
463
463
self .module .fail_json (msg = 'Error removing user %s: %s' % (self .parameters ['name' ], to_native (error )),
464
464
exception = traceback .format_exc ())
465
465
466
+ @staticmethod
467
+ def is_repeated_password (message ):
468
+ return message .startswith ('New password must be different than last 6 passwords.' ) \
469
+ or message .startswith ('New password must be different from last 6 passwords.' ) \
470
+ or message .startswith ('New password must be different than the old password.' ) \
471
+ or message .startswith ('New password must be different from the old password.' )
472
+
466
473
def change_password_rest (self , useruuid , username ):
467
474
data = {
468
475
'password' : self .parameters ['set_password' ],
@@ -474,7 +481,12 @@ def change_password_rest(self, useruuid, username):
474
481
api = "security/accounts/%s/%s" % (useruuid , username )
475
482
dummy , error = self .restApi .patch (api , data , params )
476
483
if error :
477
- self .module .fail_json (msg = 'Error while updating user password: %s' % error )
484
+ if 'message' in error and self .is_repeated_password (error ['message' ]):
485
+ # if the password is reused, assume idempotency
486
+ return False
487
+ else :
488
+ self .module .fail_json (msg = 'Error while updating user password: %s' % error )
489
+ return True
478
490
479
491
def change_password (self ):
480
492
"""
@@ -497,11 +509,7 @@ def change_password(self):
497
509
if to_native (error .code ) == '13114' :
498
510
return False
499
511
# if the user give the same password, instead of returning an error, return ok
500
- if to_native (error .code ) == '13214' and \
501
- (error .message .startswith ('New password must be different than last 6 passwords.' )
502
- or error .message .startswith ('New password must be different from last 6 passwords.' )
503
- or error .message .startswith ('New password must be different than the old password.' )
504
- or error .message .startswith ('New password must be different from the old password.' )):
512
+ if to_native (error .code ) == '13214' and self .is_repeated_password (error .message ):
505
513
return False
506
514
self .module .fail_json (msg = 'Error setting password for user %s: %s' % (self .parameters ['name' ], to_native (error )),
507
515
exception = traceback .format_exc ())
@@ -565,21 +573,20 @@ def apply_for_rest(self):
565
573
if self .module .check_mode :
566
574
pass
567
575
else :
568
- lock_user = False
569
576
if cd_action == 'create' :
570
577
self .create_user_rest (self .parameters ['applications' ])
571
578
elif cd_action == 'delete' :
572
579
self .delete_user_rest ()
573
580
elif modify_decision :
574
- if 'role_name' in modify_decision or 'applications in modify_decision' :
581
+ if 'role_name' in modify_decision or 'applications' in modify_decision :
575
582
self .modify_apps_rest (uuid , name , self .parameters ['applications' ])
576
583
if 'lock_user' in modify_decision :
577
584
self .lock_unlock_user_rest (uuid , name , self .parameters ['lock_user' ])
578
585
579
586
if not cd_action and self .parameters .get ('set_password' ) is not None :
580
- # set_password is not idempotent, as we cannot check against the previous password
581
- self .change_password_rest (uuid , name )
582
- self .na_helper .changed = True
587
+ # if check_mode, don't attempt to change the password, but assume it would be changed
588
+ if self .module . check_mode or self . change_password_rest (uuid , name ):
589
+ self .na_helper .changed = True
583
590
self .module .exit_json (changed = self .na_helper .changed )
584
591
585
592
def apply (self ):
0 commit comments