|
|
d9912c |
From 22d8784da29dcfede0744ef6b691b4506eae5deb Mon Sep 17 00:00:00 2001
|
|
|
d9912c |
From: Thomas Woerner <twoerner@redhat.com>
|
|
|
d9912c |
Date: Thu, 20 Feb 2020 12:58:11 +0100
|
|
|
d9912c |
Subject: [PATCH] ipahost: Do not fail on missing DNS or zone when no IP
|
|
|
d9912c |
address given
|
|
|
d9912c |
|
|
|
d9912c |
If no IP address is given and either DNS is not configured or if the zone is
|
|
|
d9912c |
not found then ipahost may not fail in dnsrecord_find.
|
|
|
d9912c |
|
|
|
d9912c |
The error happened for example by ensuring the absence of a host that is not
|
|
|
d9912c |
part of the domain or for a host that has been added with force and is using
|
|
|
d9912c |
a domain that is not served by the DNS server in the domain. It also
|
|
|
d9912c |
happened if there was no DNS server in the domain at all.
|
|
|
d9912c |
|
|
|
d9912c |
A new test case has been added to test_host_ipaddresses.yml
|
|
|
d9912c |
|
|
|
d9912c |
The fix requires ipalib_errors provided by ansible_freeipa_module.
|
|
|
d9912c |
|
|
|
d9912c |
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1804838
|
|
|
d9912c |
---
|
|
|
d9912c |
plugins/modules/ipahost.py | 17 +++++++++++++++--
|
|
|
d9912c |
tests/host/test_host_ipaddresses.yml | 9 +++++++++
|
|
|
d9912c |
2 files changed, 24 insertions(+), 2 deletions(-)
|
|
|
d9912c |
|
|
|
d9912c |
diff --git a/plugins/modules/ipahost.py b/plugins/modules/ipahost.py
|
|
|
d9912c |
index 558560e..062f768 100644
|
|
|
d9912c |
--- a/plugins/modules/ipahost.py
|
|
|
d9912c |
+++ b/plugins/modules/ipahost.py
|
|
|
d9912c |
@@ -409,7 +409,7 @@
|
|
|
d9912c |
from ansible.module_utils.ansible_freeipa_module import temp_kinit, \
|
|
|
d9912c |
temp_kdestroy, valid_creds, api_connect, api_command, compare_args_ipa, \
|
|
|
d9912c |
module_params_get, gen_add_del_lists, encode_certificate, api_get_realm, \
|
|
|
d9912c |
- is_ipv4_addr, is_ipv6_addr
|
|
|
d9912c |
+ is_ipv4_addr, is_ipv6_addr, ipalib_errors
|
|
|
d9912c |
import six
|
|
|
d9912c |
|
|
|
d9912c |
|
|
|
d9912c |
@@ -871,7 +871,20 @@ def main():
|
|
|
d9912c |
|
|
|
d9912c |
# Make sure host exists
|
|
|
d9912c |
res_find = find_host(ansible_module, name)
|
|
|
d9912c |
- res_find_dnsrecord = find_dnsrecord(ansible_module, name)
|
|
|
d9912c |
+ try:
|
|
|
d9912c |
+ res_find_dnsrecord = find_dnsrecord(ansible_module, name)
|
|
|
d9912c |
+ except ipalib_errors.NotFound as e:
|
|
|
d9912c |
+ msg = str(e)
|
|
|
d9912c |
+ if ip_address is None and \
|
|
|
d9912c |
+ ("DNS is not configured" in msg or \
|
|
|
d9912c |
+ "DNS zone not found" in msg):
|
|
|
d9912c |
+ # IP address(es) not given and no DNS support in IPA
|
|
|
d9912c |
+ # -> Ignore failure
|
|
|
d9912c |
+ # IP address(es) not given and DNS zone is not found
|
|
|
d9912c |
+ # -> Ignore failure
|
|
|
d9912c |
+ res_find_dnsrecord = None
|
|
|
d9912c |
+ else:
|
|
|
d9912c |
+ ansible_module.fail_json(msg="%s: %s" % (host, msg))
|
|
|
d9912c |
|
|
|
d9912c |
# Create command
|
|
|
d9912c |
if state == "present":
|
|
|
d9912c |
diff --git a/tests/host/test_host_ipaddresses.yml b/tests/host/test_host_ipaddresses.yml
|
|
|
d9912c |
index 0a97dd5..136a610 100644
|
|
|
d9912c |
--- a/tests/host/test_host_ipaddresses.yml
|
|
|
d9912c |
+++ b/tests/host/test_host_ipaddresses.yml
|
|
|
d9912c |
@@ -301,6 +301,15 @@
|
|
|
d9912c |
register: result
|
|
|
d9912c |
failed_when: result.changed
|
|
|
d9912c |
|
|
|
d9912c |
+ - name: Absent host01.ihavenodns.info test
|
|
|
d9912c |
+ ipahost:
|
|
|
d9912c |
+ ipaadmin_password: MyPassword123
|
|
|
d9912c |
+ hosts:
|
|
|
d9912c |
+ - name: host01.ihavenodns.info
|
|
|
d9912c |
+ state: absent
|
|
|
d9912c |
+ register: result
|
|
|
d9912c |
+ failed_when: result.changed
|
|
|
d9912c |
+
|
|
|
d9912c |
- name: Host absent
|
|
|
d9912c |
ipahost:
|
|
|
d9912c |
ipaadmin_password: MyPassword123
|
|
|
d9912c |
From 4d94cb09a9fb09dd2576223b9be7f77d515202fb Mon Sep 17 00:00:00 2001
|
|
|
d9912c |
From: Thomas Woerner <twoerner@redhat.com>
|
|
|
d9912c |
Date: Thu, 20 Feb 2020 12:54:32 +0100
|
|
|
d9912c |
Subject: [PATCH] ansible_freeipa_module: Import ipalib.errors as ipalib_errors
|
|
|
d9912c |
|
|
|
d9912c |
For beeing able to catch ipalib.errors.NotFound errors in ipahost it is
|
|
|
d9912c |
needed to import ipalib.errors. ipalib.errors is now imported as
|
|
|
d9912c |
ipalib_errors to not have name conflicts with the errors list used in some
|
|
|
d9912c |
of the modules.
|
|
|
d9912c |
|
|
|
d9912c |
Related: https://bugzilla.redhat.com/show_bug.cgi?id=1804838
|
|
|
d9912c |
---
|
|
|
d9912c |
plugins/module_utils/ansible_freeipa_module.py | 1 +
|
|
|
d9912c |
1 file changed, 1 insertion(+)
|
|
|
d9912c |
|
|
|
d9912c |
diff --git a/plugins/module_utils/ansible_freeipa_module.py b/plugins/module_utils/ansible_freeipa_module.py
|
|
|
d9912c |
index 6acdbef..5066de3 100644
|
|
|
d9912c |
--- a/plugins/module_utils/ansible_freeipa_module.py
|
|
|
d9912c |
+++ b/plugins/module_utils/ansible_freeipa_module.py
|
|
|
d9912c |
@@ -28,6 +28,7 @@
|
|
|
d9912c |
import gssapi
|
|
|
d9912c |
from datetime import datetime
|
|
|
d9912c |
from ipalib import api
|
|
|
d9912c |
+from ipalib import errors as ipalib_errors
|
|
|
d9912c |
from ipalib.config import Env
|
|
|
d9912c |
from ipalib.constants import DEFAULT_CONFIG, LDAP_GENERALIZED_TIME_FORMAT
|
|
|
d9912c |
try:
|