diff --git a/plugins/modules/ipahost.py b/plugins/modules/ipahost.py index 4778386cfd237f235897287b9bfe8bb46073ce6c..f0a42317f331d4b18ee3ae9d89dc8d84303447eb 100644 --- a/plugins/modules/ipahost.py +++ b/plugins/modules/ipahost.py @@ -444,24 +444,19 @@ def find_dnsrecord(module, name): _args = { "all": True, - "idnsname": to_text(host_name), + "idnsname": to_text(host_name) } - _result = api_command(module, "dnsrecord_find", to_text(domain_name), - _args) - - if len(_result["result"]) > 1: - module.fail_json( - msg="There is more than one host '%s'" % (name)) - elif len(_result["result"]) == 1: - _res = _result["result"][0] - certs = _res.get("usercertificate") - if certs is not None: - _res["usercertificate"] = [encode_certificate(cert) for - cert in certs] - return _res - else: - return None + try: + _result = api_command(module, "dnsrecord_show", to_text(domain_name), + _args) + except ipalib_errors.NotFound as e: + msg = str(e) + if "record not found" in msg: + return None + module.fail_json(msg="dnsrecord_show failed: %s" % msg) + + return _result["result"] def show_host(module, name):