Blame SOURCES/ansible-freeipa-0.1.8-ipahost-Fail-on-action-member-for-new-hosts-fix-dnsrecord_add-reverse-flag_rhbz#1803026.patch

7d56d3
From 0816b0773b1535780c7c3e5f05bda39434ab6bac Mon Sep 17 00:00:00 2001
7d56d3
From: Thomas Woerner <twoerner@redhat.com>
7d56d3
Date: Fri, 14 Feb 2020 13:21:54 +0100
7d56d3
Subject: [PATCH] ipahost: Fail on action member for new hosts, fix
7d56d3
 dnsrecord_add reverse flag
7d56d3
7d56d3
The check to make sure that member can not be used on non existing hosts
7d56d3
has bee missing. Also the reverse flag for the dnsrecord_add call was None
7d56d3
if the varaible was not set.
7d56d3
7d56d3
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1803026
7d56d3
---
7d56d3
 plugins/modules/ipahost.py | 23 +++++++++++++++--------
7d56d3
 1 file changed, 15 insertions(+), 8 deletions(-)
7d56d3
7d56d3
diff --git a/plugins/modules/ipahost.py b/plugins/modules/ipahost.py
7d56d3
index a5fd482..558560e 100644
7d56d3
--- a/plugins/modules/ipahost.py
7d56d3
+++ b/plugins/modules/ipahost.py
7d56d3
@@ -1005,6 +1005,11 @@ def main():
7d56d3
                                 dnsrecord_args.get("aaaarecord"),
7d56d3
                                 _dnsrec.get("aaaarecord"))
7d56d3
 
7d56d3
+                else:
7d56d3
+                    if res_find is None:
7d56d3
+                        ansible_module.fail_json(
7d56d3
+                            msg="No host '%s'" % name)
7d56d3
+
7d56d3
                 if action != "host" or (action == "host" and res_find is None):
7d56d3
                     certificate_add = certificate or []
7d56d3
                     certificate_del = []
7d56d3
@@ -1178,15 +1183,17 @@ def main():
7d56d3
                     domain_name = name[name.find(".")+1:]
7d56d3
                     host_name = name[:name.find(".")]
7d56d3
 
7d56d3
+                    _args = {"idnsname": host_name}
7d56d3
+                    if reverse is not None:
7d56d3
+                        _args["a_extra_create_reverse"] = reverse
7d56d3
+                        _args["aaaa_extra_create_reverse"] = reverse
7d56d3
+                    if len(dnsrecord_a_add) > 0:
7d56d3
+                        _args["arecord"] = dnsrecord_a_add
7d56d3
+                    if len(dnsrecord_aaaa_add) > 0:
7d56d3
+                        _args["aaaarecord"] = dnsrecord_aaaa_add
7d56d3
+
7d56d3
                     commands.append([domain_name,
7d56d3
-                                     "dnsrecord_add",
7d56d3
-                                     {
7d56d3
-                                         "idnsname": host_name,
7d56d3
-                                         "arecord": dnsrecord_a_add,
7d56d3
-                                         "a_extra_create_reverse": reverse,
7d56d3
-                                         "aaaarecord": dnsrecord_aaaa_add,
7d56d3
-                                         "aaaa_extra_create_reverse": reverse
7d56d3
-                                     }])
7d56d3
+                                     "dnsrecord_add", _args])
7d56d3
 
7d56d3
                 if len(dnsrecord_a_del) > 0 or len(dnsrecord_aaaa_del) > 0:
7d56d3
                     domain_name = name[name.find(".")+1:]