mirror of
https://github.com/ansible/awx.git
synced 2026-03-13 23:17:32 -02:30
Add option update_password (always, on_create) to tower_user module
This commit is contained in:
committed by
Alan Rominger
parent
ef3a497c42
commit
8e97214309
@@ -55,6 +55,13 @@ options:
|
|||||||
description:
|
description:
|
||||||
- Write-only field used to change the password.
|
- Write-only field used to change the password.
|
||||||
type: str
|
type: str
|
||||||
|
update_password:
|
||||||
|
description:
|
||||||
|
- C(always) will update passwords if they differ.
|
||||||
|
- C(on_create) will only set the password for newly created users.
|
||||||
|
type: str
|
||||||
|
choices: [ always, on_create ]
|
||||||
|
default: always
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- Desired state of the resource.
|
- Desired state of the resource.
|
||||||
@@ -115,6 +122,7 @@ def main():
|
|||||||
is_superuser=dict(type='bool', default=False, aliases=['superuser']),
|
is_superuser=dict(type='bool', default=False, aliases=['superuser']),
|
||||||
is_system_auditor=dict(type='bool', default=False, aliases=['auditor']),
|
is_system_auditor=dict(type='bool', default=False, aliases=['auditor']),
|
||||||
password=dict(no_log=True),
|
password=dict(no_log=True),
|
||||||
|
update_password=dict(choices=['always', 'on_create'], default='always', no_log=False),
|
||||||
state=dict(choices=['present', 'absent'], default='present'),
|
state=dict(choices=['present', 'absent'], default='present'),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -129,6 +137,7 @@ def main():
|
|||||||
is_superuser = module.params.get('is_superuser')
|
is_superuser = module.params.get('is_superuser')
|
||||||
is_system_auditor = module.params.get('is_system_auditor')
|
is_system_auditor = module.params.get('is_system_auditor')
|
||||||
password = module.params.get('password')
|
password = module.params.get('password')
|
||||||
|
update_password = module.params.get('update_password')
|
||||||
state = module.params.get('state')
|
state = module.params.get('state')
|
||||||
|
|
||||||
# Attempt to look up the related items the user specified (these will fail the module if not found)
|
# Attempt to look up the related items the user specified (these will fail the module if not found)
|
||||||
@@ -154,7 +163,7 @@ def main():
|
|||||||
new_fields['is_superuser'] = is_superuser
|
new_fields['is_superuser'] = is_superuser
|
||||||
if is_system_auditor:
|
if is_system_auditor:
|
||||||
new_fields['is_system_auditor'] = is_system_auditor
|
new_fields['is_system_auditor'] = is_system_auditor
|
||||||
if password:
|
if password and (not existing_item or update_password == 'always'):
|
||||||
new_fields['password'] = password
|
new_fields['password'] = password
|
||||||
|
|
||||||
# If the state was present and we can let the module build or update the existing item, this will return on its own
|
# If the state was present and we can let the module build or update the existing item, this will return on its own
|
||||||
|
|||||||
@@ -44,3 +44,16 @@ def test_password_no_op_warning(run_module, admin_user, mock_auth_stuff, silence
|
|||||||
silence_warning.assert_called_once_with(
|
silence_warning.assert_called_once_with(
|
||||||
"The field password of user {0} has encrypted data and "
|
"The field password of user {0} has encrypted data and "
|
||||||
"may inaccurately report task is changed.".format(result['id']))
|
"may inaccurately report task is changed.".format(result['id']))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_update_password_on_create(run_module, admin_user, mock_auth_stuff):
|
||||||
|
for i in range(2):
|
||||||
|
result = run_module('tower_user', dict(
|
||||||
|
username='Bob',
|
||||||
|
password='pass4word',
|
||||||
|
update_password='on_create'
|
||||||
|
), admin_user)
|
||||||
|
assert not result.get('failed', False), result.get('msg', result)
|
||||||
|
|
||||||
|
assert not result.get('changed')
|
||||||
|
|||||||
Reference in New Issue
Block a user