ipaserver_prepare: Properly report error, do show trace back

The raises of RuntimeError, ValueError and ScriptError are currently not
properly handled in ipaserver_prepare. This results in a trace back error
shown in Ansible instead of only showing the error message.

This happened for example if a nameserver is in /etc/resolv.conf that is
not reachable.
This commit is contained in:
Thomas Woerner
2019-07-02 13:38:41 +02:00
parent da2631d923
commit 115f96d0be

View File

@@ -195,96 +195,102 @@ def main():
if not options.ca_subject: if not options.ca_subject:
options.ca_subject = str(default_ca_subject_dn(options.subject_base)) options.ca_subject = str(default_ca_subject_dn(options.subject_base))
# Configuration for ipalib, we will bootstrap and finalize later, after try:
# we are sure we have the configuration file ready.
cfg = dict(
context='installer',
confdir=paths.ETC_IPA,
in_server=True,
# make sure host name specified by user is used instead of default
host=options.host_name,
)
if options.setup_ca:
# we have an IPA-integrated CA
cfg['ca_host'] = options.host_name
# Create the management framework config file and finalize api # Configuration for ipalib, we will bootstrap and finalize later, after
target_fname = paths.IPA_DEFAULT_CONF # we are sure we have the configuration file ready.
fd = open(target_fname, "w") cfg = dict(
fd.write("[global]\n") context='installer',
fd.write("host=%s\n" % options.host_name) confdir=paths.ETC_IPA,
fd.write("basedn=%s\n" % ipautil.realm_to_suffix(options.realm_name)) in_server=True,
fd.write("realm=%s\n" % options.realm_name) # make sure host name specified by user is used instead of default
fd.write("domain=%s\n" % options.domain_name) host=options.host_name,
fd.write("xmlrpc_uri=https://%s/ipa/xml\n" % \ )
ipautil.format_netloc(options.host_name)) if options.setup_ca:
fd.write("ldap_uri=ldapi://%%2fvar%%2frun%%2fslapd-%s.socket\n" % \ # we have an IPA-integrated CA
installutils.realm_to_serverid(options.realm_name)) cfg['ca_host'] = options.host_name
if options.setup_ca:
fd.write("enable_ra=True\n")
fd.write("ra_plugin=dogtag\n")
fd.write("dogtag_version=10\n")
else:
fd.write("enable_ra=False\n")
fd.write("ra_plugin=none\n")
fd.write("mode=production\n")
fd.close()
# Must be readable for everyone # Create the management framework config file and finalize api
os.chmod(target_fname, 0o644) target_fname = paths.IPA_DEFAULT_CONF
fd = open(target_fname, "w")
fd.write("[global]\n")
fd.write("host=%s\n" % options.host_name)
fd.write("basedn=%s\n" % ipautil.realm_to_suffix(options.realm_name))
fd.write("realm=%s\n" % options.realm_name)
fd.write("domain=%s\n" % options.domain_name)
fd.write("xmlrpc_uri=https://%s/ipa/xml\n" % \
ipautil.format_netloc(options.host_name))
fd.write("ldap_uri=ldapi://%%2fvar%%2frun%%2fslapd-%s.socket\n" % \
installutils.realm_to_serverid(options.realm_name))
if options.setup_ca:
fd.write("enable_ra=True\n")
fd.write("ra_plugin=dogtag\n")
fd.write("dogtag_version=10\n")
else:
fd.write("enable_ra=False\n")
fd.write("ra_plugin=none\n")
fd.write("mode=production\n")
fd.close()
api.bootstrap(**cfg) # Must be readable for everyone
api.finalize() os.chmod(target_fname, 0o644)
if options.setup_ca: api.bootstrap(**cfg)
with redirect_stdout(ansible_log): api.finalize()
ca.install_check(False, None, options)
if options.setup_kra:
with redirect_stdout(ansible_log):
kra.install_check(api, None, options)
if options.setup_dns: if options.setup_ca:
with redirect_stdout(ansible_log): with redirect_stdout(ansible_log):
dns.install_check(False, api, False, options, options.host_name) ca.install_check(False, None, options)
ip_addresses = dns.ip_addresses if options.setup_kra:
else: with redirect_stdout(ansible_log):
ip_addresses = get_server_ip_address(options.host_name, kra.install_check(api, None, options)
not options.interactive, False,
options.ip_addresses)
# check addresses here, dns module is doing own check if options.setup_dns:
no_matching_interface_for_ip_address_warning(ip_addresses) with redirect_stdout(ansible_log):
options.ip_addresses = ip_addresses dns.install_check(False, api, False, options, options.host_name)
options.reverse_zones = dns.reverse_zones ip_addresses = dns.ip_addresses
else:
ip_addresses = get_server_ip_address(options.host_name,
not options.interactive, False,
options.ip_addresses)
instance_name = "-".join(options.realm_name.split(".")) # check addresses here, dns module is doing own check
dirsrv = services.knownservices.dirsrv no_matching_interface_for_ip_address_warning(ip_addresses)
if (options.external_cert_files options.ip_addresses = ip_addresses
and dirsrv.is_installed(instance_name) options.reverse_zones = dns.reverse_zones
and not dirsrv.is_running(instance_name)):
logger.debug('Starting Directory Server')
services.knownservices.dirsrv.start(instance_name)
if options.setup_adtrust: instance_name = "-".join(options.realm_name.split("."))
with redirect_stdout(ansible_log): dirsrv = services.knownservices.dirsrv
adtrust.install_check(False, options, api) if (options.external_cert_files
and dirsrv.is_installed(instance_name)
and not dirsrv.is_running(instance_name)):
logger.debug('Starting Directory Server')
services.knownservices.dirsrv.start(instance_name)
_update_hosts_file = False if options.setup_adtrust:
# options needs to update hosts file when DNS subsystem will be with redirect_stdout(ansible_log):
# installed or custom addresses are used adtrust.install_check(False, options, api)
if options.ip_addresses or options.setup_dns:
_update_hosts_file = True
if options._host_name_overridden: _update_hosts_file = False
tasks.backup_hostname(fstore, sstore) # options needs to update hosts file when DNS subsystem will be
tasks.set_hostname(options.host_name) # installed or custom addresses are used
if options.ip_addresses or options.setup_dns:
_update_hosts_file = True
if _update_hosts_file: if options._host_name_overridden:
update_hosts_file(ip_addresses, options.host_name, fstore) tasks.backup_hostname(fstore, sstore)
tasks.set_hostname(options.host_name)
if hasattr(tasks, "configure_pkcs11_modules"): if _update_hosts_file:
if tasks.configure_pkcs11_modules(fstore): update_hosts_file(ip_addresses, options.host_name, fstore)
ansible_log.info("Disabled p11-kit-proxy")
if hasattr(tasks, "configure_pkcs11_modules"):
if tasks.configure_pkcs11_modules(fstore):
ansible_log.info("Disabled p11-kit-proxy")
except (RuntimeError, ValueError, ScriptError,
ipautil.CalledProcessError) as e:
ansible_module.fail_json(msg=str(e))
ansible_module.exit_json(changed=True, ansible_module.exit_json(changed=True,
### basic ### ### basic ###