ipareplica_prepare: Fail with proper error messages

Some errors have been printed to the error log only and fail_json only got
an empty string as error message. This made the causes of the errors hard
to get.
This commit is contained in:
Thomas Woerner
2019-07-17 19:25:25 +02:00
parent 14cb100a91
commit 18a07e2294

View File

@@ -559,7 +559,7 @@ def main():
"command on the master and use a prep file to install " "command on the master and use a prep file to install "
"this replica.") "this replica.")
logger.error("%s", msg) logger.error("%s", msg)
raise ScriptError(rval=3) raise ScriptError(msg, rval=3)
ansible_log.debug("-- CHECK DNS_MASTERS --") ansible_log.debug("-- CHECK DNS_MASTERS --")
@@ -597,21 +597,24 @@ def main():
config.ca_host_name = ca_host config.ca_host_name = ca_host
ca_enabled = True ca_enabled = True
if options.dirsrv_cert_files: if options.dirsrv_cert_files:
logger.error("Certificates could not be provided when " msg = ("Certificates could not be provided when "
"CA is present on some master.") "CA is present on some master.")
raise ScriptError(rval=3) logger.error(msg)
raise ScriptError(msg, rval=3)
else: else:
if options.setup_ca: if options.setup_ca:
logger.error("The remote master does not have a CA " msg = ("The remote master does not have a CA "
"installed, can't set up CA") "installed, can't set up CA")
raise ScriptError(rval=3) logger.error(msg)
raise ScriptError(msg, rval=3)
ca_enabled = False ca_enabled = False
if not options.dirsrv_cert_files: if not options.dirsrv_cert_files:
logger.error("Cannot issue certificates: a CA is not " msg = ("Cannot issue certificates: a CA is not "
"installed. Use the --http-cert-file, " "installed. Use the --http-cert-file, "
"--dirsrv-cert-file options to provide " "--dirsrv-cert-file options to provide "
"custom certificates.") "custom certificates.")
raise ScriptError(rval=3) logger.error(msg)
raise ScriptError(msg, rval=3)
ansible_log.debug("-- SEARCH FOR KRA --") ansible_log.debug("-- SEARCH FOR KRA --")
@@ -625,9 +628,10 @@ def main():
kra_enabled = True kra_enabled = True
else: else:
if options.setup_kra: if options.setup_kra:
logger.error("There is no active KRA server in the domain, " msg = ("There is no active KRA server in the domain, "
"can't setup a KRA clone") "can't setup a KRA clone")
raise ScriptError(rval=3) logger.error(msg)
raise ScriptError(msg, rval=3)
kra_enabled = False kra_enabled = False
ansible_log.debug("-- CHECK CA --") ansible_log.debug("-- CHECK CA --")
@@ -676,15 +680,18 @@ def main():
except errors.ACIError: except errors.ACIError:
logger.debug("%s", traceback.format_exc()) logger.debug("%s", traceback.format_exc())
raise ScriptError("\nInsufficient privileges to promote the server." ansible_module.fail_json(
"\nPossible issues:" msg = ("\nInsufficient privileges to promote the server."
"\n- A user has insufficient privileges" "\nPossible issues:"
"\n- This client has insufficient privileges " "\n- A user has insufficient privileges"
"to become an IPA replica") "\n- This client has insufficient privileges "
"to become an IPA replica"))
except errors.LDAPError: except errors.LDAPError:
logger.debug("%s", traceback.format_exc()) logger.debug("%s", traceback.format_exc())
raise ScriptError("\nUnable to connect to LDAP server %s" % ansible_module.fail_json(msg="\nUnable to connect to LDAP server %s" %
config.master_host_name) config.master_host_name)
except ScriptError as e:
ansible_module.fail_json(msg=str(e))
finally: finally:
if replman and replman.conn: if replman and replman.conn:
ansible_log.debug("-- UNBIND REPLMAN--") ansible_log.debug("-- UNBIND REPLMAN--")