Skip to content
This repository was archived by the owner on Feb 24, 2022. It is now read-only.

Commit c51ec61

Browse files
committed
Sync bitbucket and Github
1 parent 499ce62 commit c51ec61

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

ansible_collections/netapp/ontap/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Join our Slack Channel at [Netapp.io](http://netapp.io/slack)
2727
### Bug Fixes
2828
- na_ontap_firmware_upgrade: images are not downloaded, but the module reports success.
2929
- na_ontap_user: fixed KeyError if password is not provided.
30+
- na_ontap_password: do not error out if password is identical to previous password (idempotency).
3031

3132
## 20.6.0
3233

ansible_collections/netapp/ontap/plugins/modules/na_ontap_user.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,9 @@ def __init__(self):
238238
'privacy_password', 'privacy_protocol']
239239
used_unsupported_rest_properties = [x for x in unsupported_rest_properties if x in self.parameters]
240240
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:
244244
if not HAS_NETAPP_LIB:
245245
self.module.fail_json(msg="the python NetApp-Lib module is required")
246246
else:
@@ -272,7 +272,7 @@ def get_user_details_rest(self, name, uuid):
272272
return_value = {
273273
'lock_user': message['locked'],
274274
'role_name': message['role']['name'],
275-
'applications': message['applications']
275+
'applications': [app['application'] for app in message['applications']]
276276
}
277277
return return_value
278278

@@ -463,6 +463,13 @@ def delete_user(self, application):
463463
self.module.fail_json(msg='Error removing user %s: %s' % (self.parameters['name'], to_native(error)),
464464
exception=traceback.format_exc())
465465

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+
466473
def change_password_rest(self, useruuid, username):
467474
data = {
468475
'password': self.parameters['set_password'],
@@ -474,7 +481,12 @@ def change_password_rest(self, useruuid, username):
474481
api = "security/accounts/%s/%s" % (useruuid, username)
475482
dummy, error = self.restApi.patch(api, data, params)
476483
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
478490

479491
def change_password(self):
480492
"""
@@ -497,11 +509,7 @@ def change_password(self):
497509
if to_native(error.code) == '13114':
498510
return False
499511
# 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):
505513
return False
506514
self.module.fail_json(msg='Error setting password for user %s: %s' % (self.parameters['name'], to_native(error)),
507515
exception=traceback.format_exc())
@@ -565,21 +573,20 @@ def apply_for_rest(self):
565573
if self.module.check_mode:
566574
pass
567575
else:
568-
lock_user = False
569576
if cd_action == 'create':
570577
self.create_user_rest(self.parameters['applications'])
571578
elif cd_action == 'delete':
572579
self.delete_user_rest()
573580
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:
575582
self.modify_apps_rest(uuid, name, self.parameters['applications'])
576583
if 'lock_user' in modify_decision:
577584
self.lock_unlock_user_rest(uuid, name, self.parameters['lock_user'])
578585

579586
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
583590
self.module.exit_json(changed=self.na_helper.changed)
584591

585592
def apply(self):

0 commit comments

Comments
 (0)