mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-08-01 12:24:43 +00:00
Merge pull request #1058 from t-woerner/ipahost_make_return_value_depending_on_hosts_param
ipahost: Make return value depending on hosts parameter
This commit is contained in:
@@ -372,8 +372,8 @@ There are only return values if one or more random passwords have been generated
|
|||||||
Variable | Description | Returned When
|
Variable | Description | Returned When
|
||||||
-------- | ----------- | -------------
|
-------- | ----------- | -------------
|
||||||
`host` | Host dict with random password. (dict) <br>Options: | If random is yes and host did not exist or update_password is yes
|
`host` | Host dict with random password. (dict) <br>Options: | If random is yes and host did not exist or update_password is yes
|
||||||
| `randompassword` - The generated random password | If only one host is handled by the module
|
| `randompassword` - The generated random password | If only one host is handled by the module without using the `hosts` parameter.
|
||||||
| `name` - The host name of the host that got a new random password. (dict) <br> Options: <br> `randompassword` - The generated random password | If several hosts are handled by the module
|
| `name` - The host name of the host that got a new random password. (dict) <br> Options: <br> `randompassword` - The generated random password | If several hosts are handled by the module with the `hosts` parameter.
|
||||||
|
|
||||||
|
|
||||||
Authors
|
Authors
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ options:
|
|||||||
aliases: ["fqdn"]
|
aliases: ["fqdn"]
|
||||||
required: false
|
required: false
|
||||||
hosts:
|
hosts:
|
||||||
description: The list of user host dicts
|
description: The list of host dicts
|
||||||
required: false
|
required: false
|
||||||
type: list
|
type: list
|
||||||
elements: dict
|
elements: dict
|
||||||
@@ -466,16 +466,18 @@ EXAMPLES = """
|
|||||||
RETURN = """
|
RETURN = """
|
||||||
host:
|
host:
|
||||||
description: Host dict with random password
|
description: Host dict with random password
|
||||||
returned: If random is yes and user did not exist or update_password is yes
|
returned: If random is yes and host did not exist or update_password is yes
|
||||||
type: dict
|
type: dict
|
||||||
contains:
|
contains:
|
||||||
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 host is handled by the module without using hosts parameter
|
||||||
name:
|
name:
|
||||||
description: The user name of the user that got a new random password
|
description: The host name of the host that got a new random password
|
||||||
returned: If several users are handled by the module
|
returned: |
|
||||||
|
If several hosts are handled by the module with the hosts parameter
|
||||||
type: dict
|
type: dict
|
||||||
contains:
|
contains:
|
||||||
randompassword:
|
randompassword:
|
||||||
@@ -646,10 +648,10 @@ def check_parameters( # pylint: disable=unused-argument
|
|||||||
|
|
||||||
# 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_host):
|
||||||
if "random" in args and command in ["host_add", "host_mod"] \
|
if "random" in args and command in ["host_add", "host_mod"] \
|
||||||
and "randompassword" in result["result"]:
|
and "randompassword" in result["result"]:
|
||||||
if one_name:
|
if single_host:
|
||||||
exit_args["randompassword"] = \
|
exit_args["randompassword"] = \
|
||||||
result["result"]["randompassword"]
|
result["result"]["randompassword"]
|
||||||
else:
|
else:
|
||||||
@@ -671,7 +673,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_host):
|
||||||
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:
|
||||||
@@ -1468,7 +1470,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_host=hosts is None)
|
||||||
|
|
||||||
# Done
|
# Done
|
||||||
|
|
||||||
|
|||||||
@@ -49,6 +49,26 @@
|
|||||||
- "{{ host1_fqdn }}"
|
- "{{ host1_fqdn }}"
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
|
- name: Host "{{ host1_fqdn }}" is present with random password using hosts parameter
|
||||||
|
ipahost:
|
||||||
|
ipaadmin_password: SomeADMINpassword
|
||||||
|
hosts:
|
||||||
|
- name: "{{ host1_fqdn }}"
|
||||||
|
random: yes
|
||||||
|
force: yes
|
||||||
|
update_password: on_create
|
||||||
|
register: ipahost
|
||||||
|
failed_when: not ipahost.changed or
|
||||||
|
ipahost.host[host1_fqdn].randompassword is not defined or
|
||||||
|
ipahost.failed
|
||||||
|
|
||||||
|
- name: Host "{{ host1_fqdn }}" absent
|
||||||
|
ipahost:
|
||||||
|
ipaadmin_password: SomeADMINpassword
|
||||||
|
name:
|
||||||
|
- "{{ host1_fqdn }}"
|
||||||
|
state: absent
|
||||||
|
|
||||||
- name: Hosts "{{ host1_fqdn }}" and "{{ host2_fqdn }}" present with random password
|
- name: Hosts "{{ host1_fqdn }}" and "{{ host2_fqdn }}" present with random password
|
||||||
ipahost:
|
ipahost:
|
||||||
ipaadmin_password: SomeADMINpassword
|
ipaadmin_password: SomeADMINpassword
|
||||||
|
|||||||
Reference in New Issue
Block a user