From a553474ca8a85b84a3fb8c34ecd3737873dcf6e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Moser?= Date: Sat, 29 Jun 2019 21:58:51 +0200 Subject: [PATCH] [2.8] purefa_user: Fix Incorrect parameter used causing crashes. (#57588) (#58544) * purefa_user: Fix Incorrect parameter used causing crashes. (#57588) (cherry picked from commit 35dcd231be4f0afe2e1ee7a53769b3de1cc5222f) * purefa_user: add previous return as an alias Avoid breaking user's playbooks in minor releases * update changelog --- ...88-purefa_user_change_api_token_to_api.yaml | 4 ++++ .../modules/storage/purestorage/purefa_user.py | 18 +++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 changelogs/fragments/57588-purefa_user_change_api_token_to_api.yaml diff --git a/changelogs/fragments/57588-purefa_user_change_api_token_to_api.yaml b/changelogs/fragments/57588-purefa_user_change_api_token_to_api.yaml new file mode 100644 index 0000000000..aef08b779a --- /dev/null +++ b/changelogs/fragments/57588-purefa_user_change_api_token_to_api.yaml @@ -0,0 +1,4 @@ +minor_changes: + - purefa_user - change module parameter ``api_token`` to ``api`` and to stop clash with known variable. + - purefa_user - change resulting facts from ``api_token`` to ``user_api`` for clarity. + An facts alias has been added, but will be removed in 2.9. (https://github.com/ansible/ansible/pull/57588) diff --git a/lib/ansible/modules/storage/purestorage/purefa_user.py b/lib/ansible/modules/storage/purestorage/purefa_user.py index 9f0619f177..68021c7b57 100644 --- a/lib/ansible/modules/storage/purestorage/purefa_user.py +++ b/lib/ansible/modules/storage/purestorage/purefa_user.py @@ -44,7 +44,7 @@ options: description: - If changing an existing password, you must provide the old password for security type: str - api_token: + api: description: - Define whether to create an API token for this user - Token can be exposed using the I(debug) module @@ -92,7 +92,7 @@ EXAMPLES = r''' api_token: e31060a7-21fc-e277-6240-25983c6c4592 debug: - msg: "API Token: {{ ansible_facts['api_token'] }}" + msg: "API Token: {{ ansible_facts['user_api'] }}" ''' RETURN = r''' @@ -128,9 +128,11 @@ def create_user(module, array): role = 'readonly' array.create_admin(module.params['name'], role=role, password=module.params['password']) - if module.params['api_token']: + if module.params['api']: try: - user_token['api_token'] = array.create_api_token(module.params['name'])['api_token'] + user_token['user_api'] = array.create_api_token(module.params['name'])['api_token'] + # Added for 2.8.2: Not breaking user's playbooks in minor releases. + user_token['api_token'] = user_token['user_api'] except Exception: array.delete_user(module.params['name']) module.fail_json(msg='Local User {0}: Creation failed'.format(module.params['name'])) @@ -153,11 +155,13 @@ def create_user(module, array): else: module.fail_json(msg='Local User Account {0}: Password change failed - ' 'Check both old and new passwords'.format(module.params['name'])) - if module.params['api_token']: + if module.params['api']: try: if not array.get_api_token(module.params['name'])['api_token'] is None: array.delete_api_token(module.params['name']) - user_token['api_token'] = array.create_api_token(module.params['name'])['api_token'] + user_token['user_api'] = array.create_api_token(module.params['name'])['api_token'] + # Added for 2.8.2: Not breaking user's playbooks in minor releases. + user_token['api_token'] = user_token['user_api'] api_changed = True except Exception: module.fail_json(msg='Local User {0}: API token change failed'.format(module.params['name'])) @@ -192,7 +196,7 @@ def main(): state=dict(type='str', default='present', choices=['absent', 'present']), password=dict(type='str', no_log=True), old_password=dict(type='str', no_log=True), - api_token=dict(type='bool', default=False), + api=dict(type='bool', default=False), )) module = AnsibleModule(argument_spec,