[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 35dcd231be)

* purefa_user: add previous return as an alias

Avoid breaking user's playbooks in minor releases

* update changelog
pull/58552/head
René Moser 7 years ago committed by Toshio Kuratomi
parent 83c04bdec5
commit a553474ca8

@ -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)

@ -44,7 +44,7 @@ options:
description: description:
- If changing an existing password, you must provide the old password for security - If changing an existing password, you must provide the old password for security
type: str type: str
api_token: api:
description: description:
- Define whether to create an API token for this user - Define whether to create an API token for this user
- Token can be exposed using the I(debug) module - Token can be exposed using the I(debug) module
@ -92,7 +92,7 @@ EXAMPLES = r'''
api_token: e31060a7-21fc-e277-6240-25983c6c4592 api_token: e31060a7-21fc-e277-6240-25983c6c4592
debug: debug:
msg: "API Token: {{ ansible_facts['api_token'] }}" msg: "API Token: {{ ansible_facts['user_api'] }}"
''' '''
RETURN = r''' RETURN = r'''
@ -128,9 +128,11 @@ def create_user(module, array):
role = 'readonly' role = 'readonly'
array.create_admin(module.params['name'], role=role, array.create_admin(module.params['name'], role=role,
password=module.params['password']) password=module.params['password'])
if module.params['api_token']: if module.params['api']:
try: 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: except Exception:
array.delete_user(module.params['name']) array.delete_user(module.params['name'])
module.fail_json(msg='Local User {0}: Creation failed'.format(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: else:
module.fail_json(msg='Local User Account {0}: Password change failed - ' module.fail_json(msg='Local User Account {0}: Password change failed - '
'Check both old and new passwords'.format(module.params['name'])) 'Check both old and new passwords'.format(module.params['name']))
if module.params['api_token']: if module.params['api']:
try: try:
if not array.get_api_token(module.params['name'])['api_token'] is None: if not array.get_api_token(module.params['name'])['api_token'] is None:
array.delete_api_token(module.params['name']) 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 api_changed = True
except Exception: except Exception:
module.fail_json(msg='Local User {0}: API token change failed'.format(module.params['name'])) 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']), state=dict(type='str', default='present', choices=['absent', 'present']),
password=dict(type='str', no_log=True), password=dict(type='str', no_log=True),
old_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, module = AnsibleModule(argument_spec,

Loading…
Cancel
Save