Skip to content

Commit 1057558

Browse files
committed
ipareplica: Use ipa-certupdate to update certs on replica install
Use ipa-certupdate to update certificates when promoting a client to a replica.
1 parent abb32ef commit 1057558

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

roles/ipareplica/library/ipareplica_prepare.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@
275275
check_domain_level_is_supported, errors, ScriptError, setup_logging,
276276
logger, check_dns_resolution, service, find_providing_server, ca, kra,
277277
dns, no_matching_interface_for_ip_address_warning, adtrust,
278-
constants, api, redirect_stdout, replica_conn_check, tasks
278+
constants, api, redirect_stdout, replica_conn_check, tasks,
279+
is_ipa_client_configured, install_ca_cert,
279280
)
280281
from ansible.module_utils import six
281282

@@ -601,10 +602,20 @@ def main():
601602
ansible_log.debug("-- CA_CRT --")
602603

603604
cafile = paths.IPA_CA_CRT
604-
if not os.path.isfile(cafile):
605-
ansible_module.fail_json(
606-
msg="CA cert file is not available! Please reinstall"
607-
"the client and try again.")
605+
if install_ca_cert is not None:
606+
if not os.path.isfile(cafile):
607+
ansible_module.fail_json(
608+
msg="CA cert file is not available! Please reinstall"
609+
"the client and try again.")
610+
else:
611+
if is_ipa_client_configured(on_master=True):
612+
# host was already an IPA client, refresh client cert stores to
613+
# ensure we have up to date CA certs.
614+
try:
615+
ipautil.run([paths.IPA_CERTUPDATE])
616+
except ipautil.CalledProcessError:
617+
ansible_module.fail_json(
618+
msg="ipa-certupdate failed to refresh certs.")
608619

609620
ansible_log.debug("-- REMOTE_API --")
610621

roles/ipareplica/module_utils/ansible_ipa_replica.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@
4949
"dnsname", "kernel_keyring", "krbinstance", "getargspec",
5050
"adtrustinstance", "paths", "api", "dsinstance", "ipaldap", "Env",
5151
"ipautil", "installutils", "IPA_PYTHON_VERSION", "NUM_VERSION",
52-
"ReplicaConfig", "create_api"]
52+
"ReplicaConfig", "create_api", "is_ipa_client_configured"]
5353

5454
import sys
5555
import logging
56+
import os.path
5657

5758
# Import getargspec from inspect or provide own getargspec for
5859
# Python 2 compatibility with Python 3.11+.
@@ -138,6 +139,19 @@ def getargspec(func):
138139
from ipalib.facts import is_ipa_configured
139140
except ImportError:
140141
from ipaserver.install.installutils import is_ipa_configured
142+
try:
143+
from ipalib.facts import is_ipa_client_configured
144+
except ImportError:
145+
def is_ipa_client_configured(_on_master=False):
146+
return (
147+
os.path.isfile(paths.IPA_DEFAULT_CONF) and
148+
os.path.isfile(
149+
os.path.join(
150+
paths.IPA_CLIENT_SYSRESTORE,
151+
sysrestore.SYSRESTORE_STATEFILE
152+
)
153+
)
154+
)
141155
from ipaserver.install.replication import (
142156
ReplicationManager, replica_conn_check)
143157
try:

0 commit comments

Comments
 (0)