mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-06-11 03:05:54 +00:00
New global ansible_ipa_client utils module
With ansible 2.3.1 it is possible to have one place as an additional utils module to do all the needed steps to be able to generate the environment for new and older ipa versions. The library modules are now a lot smaller. The minimal ansible version has been increased to 2.3.1. In the future it might now also be possible to have a special ansible_ipa_client version for ipa < 4.4 in this utils module.
This commit is contained in:
@@ -115,63 +115,9 @@ RETURN = '''
|
||||
'''
|
||||
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
import inspect
|
||||
import logging
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ipapython.version import NUM_VERSION, VERSION
|
||||
if NUM_VERSION < 40400:
|
||||
raise Exception("freeipa version '%s' is too old" % VERSION)
|
||||
try:
|
||||
from ipalib.install import sysrestore
|
||||
except ImportError:
|
||||
from ipapython import sysrestore
|
||||
from ipaplatform.paths import paths
|
||||
try:
|
||||
from ipaclient.install.client import CCACHE_FILE, configure_ssh_config, \
|
||||
configure_sshd_config, configure_automount, configure_firefox, \
|
||||
configure_nisdomain
|
||||
except ImportError:
|
||||
# Create temporary copy of ipa-client-install script (as
|
||||
# ipa_client_install.py) to be able to import the script easily and also
|
||||
# to remove the global finally clause in which the generated ccache file
|
||||
# gets removed. The ccache file will be needed in the next step.
|
||||
# This is done in a temporary directory that gets removed right after
|
||||
# ipa_client_install has been imported.
|
||||
import shutil
|
||||
temp_dir = tempfile.mkdtemp(dir="/tmp")
|
||||
sys.path.append(temp_dir)
|
||||
temp_file = "%s/ipa_client_install.py" % temp_dir
|
||||
|
||||
with open("/usr/sbin/ipa-client-install", "r") as f_in:
|
||||
with open(temp_file, "w") as f_out:
|
||||
for line in f_in:
|
||||
if line.startswith("finally:"):
|
||||
break
|
||||
f_out.write(line)
|
||||
import ipa_client_install
|
||||
|
||||
shutil.rmtree(temp_dir, ignore_errors=True)
|
||||
sys.path.remove(temp_dir)
|
||||
|
||||
argspec = inspect.getargspec(ipa_client_install.configure_nisdomain)
|
||||
if len(argspec.args) == 3:
|
||||
configure_nisdomain = ipa_client_install.configure_nisdomain
|
||||
else:
|
||||
def configure_nisdomain(options, domain, statestore=None):
|
||||
return ipa_client_install.configure_nisdomain(options, domain)
|
||||
|
||||
CCACHE_FILE = paths.IPA_DNS_CCACHE
|
||||
configure_ssh_config = ipa_client_install.configure_ssh_config
|
||||
configure_sshd_config = ipa_client_install.configure_sshd_config
|
||||
configure_automount = ipa_client_install.configure_automount
|
||||
configure_firefox = ipa_client_install.configure_firefox
|
||||
try:
|
||||
from ipaclient.install import ntpconf
|
||||
except ImportError:
|
||||
from ipaclient import ntpconf
|
||||
from ansible.module_utils.ansible_ipa_client import *
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
@@ -214,13 +160,9 @@ def main():
|
||||
|
||||
fstore = sysrestore.FileStore(paths.IPA_CLIENT_SYSRESTORE)
|
||||
statestore = sysrestore.StateFile(paths.IPA_CLIENT_SYSRESTORE)
|
||||
logger = logging.getLogger("ipa-client-install")
|
||||
|
||||
os.environ['KRB5CCNAME'] = CCACHE_FILE
|
||||
os.environ['KRB5CCNAME'] = paths.IPA_DNS_CCACHE
|
||||
|
||||
class Object(object):
|
||||
pass
|
||||
options = Object()
|
||||
options.sssd = sssd
|
||||
options.trust_sshfp = trust_sshfp
|
||||
options.location = automount_location
|
||||
@@ -254,7 +196,7 @@ def main():
|
||||
|
||||
# Cleanup: Remove CCACHE_FILE
|
||||
try:
|
||||
os.remove(CCACHE_FILE)
|
||||
os.remove(paths.IPA_DNS_CCACHE)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user