mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-07-31 11:54:47 +00:00
Merge pull request #1053 from t-woerner/ipauer_make_return_value_depending_on_users_parameter
ipauser: Make return value depending on users parameter
This commit is contained in:
@@ -434,8 +434,8 @@ There are only return values if one or more random passwords have been generated
|
|||||||
Variable | Description | Returned When
|
Variable | Description | Returned When
|
||||||
-------- | ----------- | -------------
|
-------- | ----------- | -------------
|
||||||
`user` | User dict with random password. (dict) <br>Options: | If random is yes and user did not exist or update_password is yes
|
`user` | User dict with random password. (dict) <br>Options: | If random is yes and user did not exist or update_password is yes
|
||||||
| `randompassword` - The generated random password | If only one user is handled by the module
|
| `randompassword` - The generated random password | If only one user is handled by the module without using the `users` parameter.
|
||||||
| `name` - The user name of the user that got a new random password. (dict) <br> Options: <br> `randompassword` - The generated random password | If several users are handled by the module
|
| `name` - The user name of the user that got a new random password. (dict) <br> Options: <br> `randompassword` - The generated random password | If several users are handled by the module with the `users` parameter.
|
||||||
|
|
||||||
|
|
||||||
Authors
|
Authors
|
||||||
|
|||||||
@@ -589,10 +589,12 @@ user:
|
|||||||
randompassword:
|
randompassword:
|
||||||
description: The generated random password
|
description: The generated random password
|
||||||
type: str
|
type: str
|
||||||
returned: If only one user is handled by the module
|
returned: |
|
||||||
|
If only one user is handled by the module without using users parameter
|
||||||
name:
|
name:
|
||||||
description: The user name of the user that got a new random password
|
description: The user name of the user that got a new random password
|
||||||
returned: If several users are handled by the module
|
returned: |
|
||||||
|
If several users are handled by the module with the users parameter
|
||||||
type: dict
|
type: dict
|
||||||
contains:
|
contains:
|
||||||
randompassword:
|
randompassword:
|
||||||
@@ -834,11 +836,11 @@ def gen_certmapdata_args(certmapdata):
|
|||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def result_handler(module, result, command, name, args, errors, exit_args,
|
def result_handler(module, result, command, name, args, errors, exit_args,
|
||||||
one_name):
|
single_user):
|
||||||
|
|
||||||
if "random" in args and command in ["user_add", "user_mod"] \
|
if "random" in args and command in ["user_add", "user_mod"] \
|
||||||
and "randompassword" in result["result"]:
|
and "randompassword" in result["result"]:
|
||||||
if one_name:
|
if single_user:
|
||||||
exit_args["randompassword"] = \
|
exit_args["randompassword"] = \
|
||||||
result["result"]["randompassword"]
|
result["result"]["randompassword"]
|
||||||
else:
|
else:
|
||||||
@@ -861,7 +863,7 @@ def result_handler(module, result, command, name, args, errors, exit_args,
|
|||||||
|
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def exception_handler(module, ex, errors, exit_args, one_name):
|
def exception_handler(module, ex, errors, exit_args, single_user):
|
||||||
msg = str(ex)
|
msg = str(ex)
|
||||||
if "already contains" in msg \
|
if "already contains" in msg \
|
||||||
or "does not contain" in msg:
|
or "does not contain" in msg:
|
||||||
@@ -1511,7 +1513,7 @@ def main():
|
|||||||
|
|
||||||
changed = ansible_module.execute_ipa_commands(
|
changed = ansible_module.execute_ipa_commands(
|
||||||
commands, result_handler, exception_handler,
|
commands, result_handler, exception_handler,
|
||||||
exit_args=exit_args, one_name=len(names) == 1)
|
exit_args=exit_args, single_user=users is None)
|
||||||
|
|
||||||
# Done
|
# Done
|
||||||
ansible_module.exit_json(changed=changed, user=exit_args)
|
ansible_module.exit_json(changed=changed, user=exit_args)
|
||||||
|
|||||||
@@ -36,6 +36,27 @@
|
|||||||
- user1
|
- user1
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
|
- name: User user1 is present with random password using users parameter
|
||||||
|
ipauser:
|
||||||
|
ipaadmin_password: SomeADMINpassword
|
||||||
|
users:
|
||||||
|
- name: user1
|
||||||
|
first: first1
|
||||||
|
last: last1
|
||||||
|
random: yes
|
||||||
|
update_password: on_create
|
||||||
|
register: ipauser
|
||||||
|
failed_when: not ipauser.changed or
|
||||||
|
ipauser.user.user1.randompassword is not defined or
|
||||||
|
ipauser.failed
|
||||||
|
|
||||||
|
- name: User user1 absent
|
||||||
|
ipauser:
|
||||||
|
ipaadmin_password: SomeADMINpassword
|
||||||
|
name:
|
||||||
|
- user1
|
||||||
|
state: absent
|
||||||
|
|
||||||
- name: Users user1 and user2 present with random password
|
- name: Users user1 and user2 present with random password
|
||||||
ipauser:
|
ipauser:
|
||||||
ipaadmin_password: SomeADMINpassword
|
ipaadmin_password: SomeADMINpassword
|
||||||
|
|||||||
Reference in New Issue
Block a user