|
|
fb9e9a |
From 6132a947e65fb9c3a1ec5c059aed34afb06a67df Mon Sep 17 00:00:00 2001
|
|
|
fb9e9a |
From: Thomas Woerner <twoerner@redhat.com>
|
|
|
fb9e9a |
Date: Mon, 29 Jun 2020 13:12:12 +0200
|
|
|
fb9e9a |
Subject: [PATCH] ipa[host]group: Fix membermanager unknow user issue
|
|
|
fb9e9a |
|
|
|
fb9e9a |
If a unknown membermanager user presence will be ensured, the unknown user
|
|
|
fb9e9a |
error was ignored. This has been fixed in ipagroup. The code for the error
|
|
|
fb9e9a |
handling in ipagroup and ipahostgroup has been adapted because of this.
|
|
|
fb9e9a |
|
|
|
fb9e9a |
New tests for tests/[host]group/test_[host]group_membermnager.yml have been
|
|
|
fb9e9a |
added.
|
|
|
fb9e9a |
---
|
|
|
fb9e9a |
plugins/modules/ipagroup.py | 19 +++++++++----------
|
|
|
fb9e9a |
plugins/modules/ipahostgroup.py | 13 +++++++------
|
|
|
fb9e9a |
tests/group/test_group_membermanager.yml | 11 ++++++++++-
|
|
|
fb9e9a |
.../test_hostgroup_membermanager.yml | 11 ++++++++++-
|
|
|
fb9e9a |
4 files changed, 36 insertions(+), 18 deletions(-)
|
|
|
fb9e9a |
|
|
|
fb9e9a |
diff --git a/plugins/modules/ipagroup.py b/plugins/modules/ipagroup.py
|
|
|
fb9e9a |
index 915bc499..903c256d 100644
|
|
|
fb9e9a |
--- a/plugins/modules/ipagroup.py
|
|
|
fb9e9a |
+++ b/plugins/modules/ipagroup.py
|
|
|
fb9e9a |
@@ -507,16 +507,15 @@ def main():
|
|
|
fb9e9a |
# All "already a member" and "not a member" failures in the
|
|
|
fb9e9a |
# result are ignored. All others are reported.
|
|
|
fb9e9a |
errors = []
|
|
|
fb9e9a |
- if "failed" in result and len(result["failed"]) > 0:
|
|
|
fb9e9a |
- for item in result["failed"]:
|
|
|
fb9e9a |
- failed_item = result["failed"][item]
|
|
|
fb9e9a |
- for member_type in failed_item:
|
|
|
fb9e9a |
- for member, failure in failed_item[member_type]:
|
|
|
fb9e9a |
- if "already a member" in failure \
|
|
|
fb9e9a |
- or "not a member" in failure:
|
|
|
fb9e9a |
- continue
|
|
|
fb9e9a |
- errors.append("%s: %s %s: %s" % (
|
|
|
fb9e9a |
- command, member_type, member, failure))
|
|
|
fb9e9a |
+ for failed_item in result.get("failed", []):
|
|
|
fb9e9a |
+ failed = result["failed"][failed_item]
|
|
|
fb9e9a |
+ for member_type in failed:
|
|
|
fb9e9a |
+ for member, failure in failed[member_type]:
|
|
|
fb9e9a |
+ if "already a member" in failure \
|
|
|
fb9e9a |
+ or "not a member" in failure:
|
|
|
fb9e9a |
+ continue
|
|
|
fb9e9a |
+ errors.append("%s: %s %s: %s" % (
|
|
|
fb9e9a |
+ command, member_type, member, failure))
|
|
|
fb9e9a |
if len(errors) > 0:
|
|
|
fb9e9a |
ansible_module.fail_json(msg=", ".join(errors))
|
|
|
fb9e9a |
|
|
|
fb9e9a |
diff --git a/plugins/modules/ipahostgroup.py b/plugins/modules/ipahostgroup.py
|
|
|
fb9e9a |
index 4c18e940..5f615160 100644
|
|
|
fb9e9a |
--- a/plugins/modules/ipahostgroup.py
|
|
|
fb9e9a |
+++ b/plugins/modules/ipahostgroup.py
|
|
|
fb9e9a |
@@ -423,14 +423,15 @@ def main():
|
|
|
fb9e9a |
# All "already a member" and "not a member" failures in the
|
|
|
fb9e9a |
# result are ignored. All others are reported.
|
|
|
fb9e9a |
errors = []
|
|
|
fb9e9a |
- if "failed" in result and "member" in result["failed"]:
|
|
|
fb9e9a |
- failed = result["failed"]["member"]
|
|
|
fb9e9a |
+ for failed_item in result.get("failed", []):
|
|
|
fb9e9a |
+ failed = result["failed"][failed_item]
|
|
|
fb9e9a |
for member_type in failed:
|
|
|
fb9e9a |
for member, failure in failed[member_type]:
|
|
|
fb9e9a |
- if "already a member" not in failure \
|
|
|
fb9e9a |
- and "not a member" not in failure:
|
|
|
fb9e9a |
- errors.append("%s: %s %s: %s" % (
|
|
|
fb9e9a |
- command, member_type, member, failure))
|
|
|
fb9e9a |
+ if "already a member" in failure \
|
|
|
fb9e9a |
+ or "not a member" in failure:
|
|
|
fb9e9a |
+ continue
|
|
|
fb9e9a |
+ errors.append("%s: %s %s: %s" % (
|
|
|
fb9e9a |
+ command, member_type, member, failure))
|
|
|
fb9e9a |
if len(errors) > 0:
|
|
|
fb9e9a |
ansible_module.fail_json(msg=", ".join(errors))
|
|
|
fb9e9a |
|
|
|
fb9e9a |
diff --git a/tests/group/test_group_membermanager.yml b/tests/group/test_group_membermanager.yml
|
|
|
fb9e9a |
index 1d38654f..661f26d6 100644
|
|
|
fb9e9a |
--- a/tests/group/test_group_membermanager.yml
|
|
|
fb9e9a |
+++ b/tests/group/test_group_membermanager.yml
|
|
|
fb9e9a |
@@ -8,7 +8,7 @@
|
|
|
fb9e9a |
- name: Ensure user manangeruser1 and manageruser2 is absent
|
|
|
fb9e9a |
ipauser:
|
|
|
fb9e9a |
ipaadmin_password: SomeADMINpassword
|
|
|
fb9e9a |
- name: manageruser1,manageruser2
|
|
|
fb9e9a |
+ name: manageruser1,manageruser2,unknown_user
|
|
|
fb9e9a |
state: absent
|
|
|
fb9e9a |
|
|
|
fb9e9a |
- name: Ensure group testgroup, managergroup1 and managergroup2 are absent
|
|
|
fb9e9a |
@@ -185,6 +185,15 @@
|
|
|
fb9e9a |
register: result
|
|
|
fb9e9a |
failed_when: not result.changed
|
|
|
fb9e9a |
|
|
|
fb9e9a |
+ - name: Ensure unknown membermanager_user member failure
|
|
|
fb9e9a |
+ ipagroup:
|
|
|
fb9e9a |
+ ipaadmin_password: SomeADMINpassword
|
|
|
fb9e9a |
+ name: testgroup
|
|
|
fb9e9a |
+ membermanager_user: unknown_user
|
|
|
fb9e9a |
+ action: member
|
|
|
fb9e9a |
+ register: result
|
|
|
fb9e9a |
+ failed_when: result.changed or "no such entry" not in result.msg
|
|
|
fb9e9a |
+
|
|
|
fb9e9a |
- name: Ensure group testgroup, managergroup1 and managergroup2 are absent
|
|
|
fb9e9a |
ipagroup:
|
|
|
fb9e9a |
ipaadmin_password: SomeADMINpassword
|
|
|
fb9e9a |
diff --git a/tests/hostgroup/test_hostgroup_membermanager.yml b/tests/hostgroup/test_hostgroup_membermanager.yml
|
|
|
fb9e9a |
index c32d1088..c0f65460 100644
|
|
|
fb9e9a |
--- a/tests/hostgroup/test_hostgroup_membermanager.yml
|
|
|
fb9e9a |
+++ b/tests/hostgroup/test_hostgroup_membermanager.yml
|
|
|
fb9e9a |
@@ -15,7 +15,7 @@
|
|
|
fb9e9a |
- name: Ensure user manangeruser1 and manageruser2 is absent
|
|
|
fb9e9a |
ipauser:
|
|
|
fb9e9a |
ipaadmin_password: SomeADMINpassword
|
|
|
fb9e9a |
- name: manageruser1,manageruser2
|
|
|
fb9e9a |
+ name: manageruser1,manageruser2,unknown_user
|
|
|
fb9e9a |
state: absent
|
|
|
fb9e9a |
|
|
|
fb9e9a |
- name: Ensure group managergroup1 and managergroup2 are absent
|
|
|
fb9e9a |
@@ -200,6 +200,15 @@
|
|
|
fb9e9a |
register: result
|
|
|
fb9e9a |
failed_when: not result.changed
|
|
|
fb9e9a |
|
|
|
fb9e9a |
+ - name: Ensure unknown membermanager_user member failure
|
|
|
fb9e9a |
+ ipahostgroup:
|
|
|
fb9e9a |
+ ipaadmin_password: SomeADMINpassword
|
|
|
fb9e9a |
+ name: testhostgroup
|
|
|
fb9e9a |
+ membermanager_user: unknown_user
|
|
|
fb9e9a |
+ action: member
|
|
|
fb9e9a |
+ register: result
|
|
|
fb9e9a |
+ failed_when: result.changed or "no such entry" not in result.msg
|
|
|
fb9e9a |
+
|
|
|
fb9e9a |
- name: Ensure host-group testhostgroup is absent
|
|
|
fb9e9a |
ipahostgroup:
|
|
|
fb9e9a |
ipaadmin_password: SomeADMINpassword
|