From ecaad8cdbcbcbea63a531ba2ac829913b59d74a6 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 21 Sep 2023 18:41:22 +0200 Subject: [PATCH] Start adoption for RHEL 9 --- bin/create-vmware-template | 4 +- etc/cobbler-distros.yaml.default | 173 ++++++++++++ lib/cr_vmware_tpl/app.py | 5 +- lib/cr_vmware_tpl/cobbler.py | 89 +++++- lib/cr_vmware_tpl/config.py | 80 +++++- lib/cr_vmware_tpl/handler.py | 6 +- templates/{el-standard.ks => el7-standard.ks} | 69 ++++- templates/el8-standard.ks | 226 ++++++++++++++++ templates/el9-standard.ks | 255 ++++++++++++++++++ 9 files changed, 891 insertions(+), 16 deletions(-) rename templates/{el-standard.ks => el7-standard.ks} (71%) create mode 100644 templates/el8-standard.ks create mode 100644 templates/el9-standard.ks diff --git a/bin/create-vmware-template b/bin/create-vmware-template index 63745de..8138855 100755 --- a/bin/create-vmware-template +++ b/bin/create-vmware-template @@ -40,7 +40,7 @@ from cr_vmware_tpl.app import CrTplApplication log = logging.getLogger(__name__) __author__ = 'Frank Brehm ' -__copyright__ = '(C) 2018 by Frank Brehm, Pixelpark GmbH, Berlin' +__copyright__ = '(C) 2023 by Frank Brehm, Pixelpark GmbH, Berlin' appname = os.path.basename(sys.argv[0]) @@ -49,7 +49,7 @@ locale.setlocale(locale.LC_ALL, '') app = CrTplApplication(appname=appname, base_dir=base_dir) app.initialized = True -if app.verbose > 2: +if app.verbose > 3: print("{c}-Object:\n{a}".format(c=app.__class__.__name__, a=app)) app() diff --git a/etc/cobbler-distros.yaml.default b/etc/cobbler-distros.yaml.default index 03acebe..72c5539 100644 --- a/etc/cobbler-distros.yaml.default +++ b/etc/cobbler-distros.yaml.default @@ -4,6 +4,8 @@ cobbler-distros: distro: 'AlmaLinux-8-x86_64' description: 'AlmaLinux 8 x86_64' shortname: 'alma8' + ks_template: 'el8-standard.ks' + is_rhel: false ks_repo_url: 'https://repo02.pixelpark.com/Linux/yum/almalinux/8/BaseOS/x86_64/os' packages: - '@core' @@ -14,6 +16,7 @@ cobbler-distros: - 'bind-utils' - 'chrony' - 'curl' + - 'dbus' - 'git' - 'iotop' - 'langpacks-de' @@ -22,6 +25,7 @@ cobbler-distros: - 'man' - 'mlocate' - 'net-tools' + - 'oddjob-mkhomedir' - 'postfix' - 'psmisc' - 'rsync' @@ -69,15 +73,19 @@ cobbler-distros: - 'tpl.280.dist-upgrade.sh' - 'tpl.300.create-motd.sh' - 'tpl.320.root-ssh-login.sh' + - 'tpl.350.legato.sh' - 'tpl.400.chrony.sh' - 'tpl.450.puppet.sh' - 'tpl.470.postfix.sh' - 'tpl.500.logrotate.sh' - 'tpl.999.finish.sh' + centos-7: distro: 'CentOS-7.9-x86_64' description: 'CentOS 7 x86_64' shortname: 'centos7' + is_rhel: false + ks_template: 'el7-standard.ks' ks_repo_url: 'https://repo02.pixelpark.com/Linux/yum/centos/7/os/x86_64' repos: - 'centos-7-x86_64-baseos' @@ -137,15 +145,19 @@ cobbler-distros: - 'tpl.280.dist-upgrade.sh' - 'tpl.300.create-motd.sh' - 'tpl.320.root-ssh-login.sh' + - 'tpl.350.legato.sh' - 'tpl.400.chrony.sh' - 'tpl.450.puppet.sh' - 'tpl.470.postfix.sh' - 'tpl.500.logrotate.sh' - 'tpl.999.finish.sh' + centos-stream-8: distro: 'CentOS-Stream-8-x86_64' description: 'CentOS Stream 8 x86_64' shortname: 'centos8' + is_rhel: false + ks_template: 'el8-standard.ks' ks_repo_url: 'https://repo02.pixelpark.com/Linux/yum/centos/8-stream/BaseOS/x86_64/os' repos: - 'centos-stream-8-x86_64-baseos' @@ -168,6 +180,7 @@ cobbler-distros: - 'bind-utils' - 'chrony' - 'curl' + - 'dbus' - 'git' - 'iotop' - 'langpacks-de' @@ -176,6 +189,7 @@ cobbler-distros: - 'man' - 'mlocate' - 'net-tools' + - 'oddjob-mkhomedir' - 'postfix' - 'psmisc' - 'rsync' @@ -211,15 +225,99 @@ cobbler-distros: - 'tpl.280.dist-upgrade.sh' - 'tpl.300.create-motd.sh' - 'tpl.320.root-ssh-login.sh' + - 'tpl.350.legato.sh' - 'tpl.400.chrony.sh' - 'tpl.450.puppet.sh' - 'tpl.470.postfix.sh' - 'tpl.500.logrotate.sh' - 'tpl.999.finish.sh' + + centos-stream-9: + distro: 'CentOS-Stream-9-x86_64' + description: 'CentOS Stream 9 x86_64' + shortname: 'centos9' + is_rhel: false + ks_template: 'el9-standard.ks' + ks_repo_url: 'https://repo02.pixelpark.com/Linux/yum/centos-stream/9-stream/BaseOS/x86_64/os' + repos: + - 'centos-stream-8-x86_64-baseos' + - 'centos-stream-8-x86_64-appstream' + - 'centos-stream-8-x86_64-extras' + - 'centos-stream-8-x86_64-powertools' + - 'epel-8-x86_64' + - 'epel-8-x86_64-modular' + - 'icinga-el8-x86_64' + - 'puppetlabs-puppet7-el8-x86_64' + - 'pixelpark-el8-x86_64' + - 'monitoring-noarch' + - 'prometheus-el8-x86_64' + packages: + - '@core' + - '@^minimal install' + - 'NetworkManager-config-server' + - 'bash-completion' + - 'bc' + - 'bind-utils' + - 'chrony' + - 'curl' + - 'dbus' + - 'git' + - 'iotop' + - 'langpacks-de' + - 'lsof' + - 'mailx' + - 'man' + - 'mlocate' + - 'net-tools' + - 'oddjob-mkhomedir' + - 'postfix' + - 'psmisc' + - 'rsync' + - 'strace' + - 'sysstat' + - 'tcpdump' + - 'telnet' + - 'tmux' + - 'traceroute' + - 'vim' + - 'wget' + - 'yum-utils' + - '-abrt*' + - '-nfs*' + - '-rpcbind' + snippets: + - 'tpl.001.basics.sh' + - 'tpl.010.authkeys.sh' + - 'tpl.040.network.sh' + - 'tpl.060.tweak_systemd.sh' + - 'tpl.070.tweak_grub.sh' + - 'tpl.075.tmp-tmpfs.sh' + - 'tpl.080.rsyslogd-el8.sh' + - 'tpl.085.disable-ipv6.sh' + - 'tpl.100.clear_repos.sh' + - 'tpl.180.repos_centos8.sh' + - 'tpl.185.repos_el8.sh' + - 'tpl.200.init-repos.sh' + - 'tpl.210.bashrc-el8.sh' + - 'tpl.220.locales-el8.sh' + - 'tpl.230.vimrc-el8.sh' + - 'tpl.250.pkgs-el8.sh' + - 'tpl.280.dist-upgrade.sh' + - 'tpl.300.create-motd.sh' + - 'tpl.320.root-ssh-login.sh' + - 'tpl.350.legato.sh' + - 'tpl.400.chrony.sh' + - 'tpl.450.puppet.sh' + - 'tpl.470.postfix.sh' + - 'tpl.500.logrotate.sh' + - 'tpl.999.finish.sh' + oel-7: distro: 'Oracle-Linux-7.9-x86_64' description: 'Oracle Enterprise Linux 7 x86_64' shortname: 'oel7' + is_rhel: false + ks_template: 'el7-standard.ks' ks_repo_url: '$tree' # ks_repo_url: 'https://repo02.pixelpark.com/Linux/yum/OracleLinux/OL7/ol7_latest' # + 'LiveOS/squashfs.img' @@ -285,15 +383,87 @@ cobbler-distros: - 'tpl.280.dist-upgrade.sh' - 'tpl.300.create-motd.sh' - 'tpl.320.root-ssh-login.sh' + - 'tpl.350.legato.sh' - 'tpl.400.chrony.sh' - 'tpl.450.puppet.sh' - 'tpl.470.postfix.sh' - 'tpl.500.logrotate.sh' - 'tpl.999.finish.sh' + + rhel-9: + distro: 'RHEL-9.2-x86_64' + description: 'RedHat Enterprise Linux 9 x86_64' + shortname: 'rhel9' + is_rhel: true + ks_template: 'el9-standard.ks' + ks_repo_url: 'http://${server}/cobbler/distro_mirror/RHEL-9.2' + repos: [] + packages: + - '@core' + - '@^minimal install' + - 'NetworkManager-config-server' + - 'bash-completion' + - 'bc' + - 'bind-utils' + - 'chrony' + - 'curl' + - 'dbus' + - 'iotop' + - 'kexec-tools' + - 'langpacks-de' + - 'lsof' + - 'man' + - 'mlocate' + - 'net-tools' + - 'oddjob-mkhomedir' + - 'psmisc' + - 'rsync' + - 's-nail' + - 'strace' + - 'sysstat' + - 'tcpdump' + - 'telnet' + - 'tmux' + - 'traceroute' + - 'vim' + - 'wget' + - 'yum-utils' + - '-abrt*' + - '-nfs*' + - '-rpcbind' + snippets: + - 'tpl.001.basics.sh' + - 'tpl.005.update_resolvconf.sh' + - 'tpl.010.authkeys.sh' + - 'tpl.040.network.sh' + - 'tpl.060.tweak_systemd.sh' + - 'tpl.070.tweak_grub.sh' + - 'tpl.075.tmp-tmpfs.sh' + - 'tpl.080.rsyslogd-el9.sh' + - 'tpl.085.disable-ipv6.sh' + - 'tpl.100.clear_repos.sh' + - 'tpl.110.register-rhel.sh' + - 'tpl.190.repos_rhel9.sh' + - 'tpl.195.repos_el9.sh' + - 'tpl.200.init-repos.sh' + - 'tpl.211.bashrc-el9.sh' + - 'tpl.220.locales-el9.sh' + - 'tpl.231.vimrc-centos9.sh' + - 'tpl.250.pkgs-el9.sh' + - 'tpl.280.dist-upgrade.sh' + - 'tpl.300.create-motd.sh' + - 'tpl.320.root-ssh-login.sh' + - 'tpl.400.chrony.sh' + - 'tpl.450.puppet.sh' + - 'tpl.500.logrotate.sh' + - 'tpl.999.finish.sh' + rocky-8: distro: 'Rocky-8-x86_64' description: 'Rocky Linux 8 x86_64' shortname: 'rocky8' + is_rhel: false + ks_template: 'el8-standard.ks' ks_repo_url: 'https://repo02.pixelpark.com/Linux/yum/rockylinux/8/BaseOS/x86_64/os' repos: - 'rocky-8-x86_64-baseos' @@ -316,6 +486,7 @@ cobbler-distros: - 'bind-utils' - 'chrony' - 'curl' + - 'dbus' - 'git' - 'iotop' - 'langpacks-de' @@ -324,6 +495,7 @@ cobbler-distros: - 'man' - 'mlocate' - 'net-tools' + - 'oddjob-mkhomedir' - 'postfix' - 'psmisc' - 'rsync' @@ -359,6 +531,7 @@ cobbler-distros: - 'tpl.280.dist-upgrade.sh' - 'tpl.300.create-motd.sh' - 'tpl.320.root-ssh-login.sh' + - 'tpl.350.legato.sh' - 'tpl.400.chrony.sh' - 'tpl.450.puppet.sh' - 'tpl.470.postfix.sh' diff --git a/lib/cr_vmware_tpl/app.py b/lib/cr_vmware_tpl/app.py index b41f3fd..63dbd4e 100644 --- a/lib/cr_vmware_tpl/app.py +++ b/lib/cr_vmware_tpl/app.py @@ -38,7 +38,7 @@ from .xlate import __base_dir__ as __xlate_base_dir__ from .xlate import __mo_file__ as __xlate_mo_file__ from .xlate import XLATOR, LOCALE_DIR, DOMAIN -__version__ = '1.5.1' +__version__ = '1.5.2' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -130,6 +130,8 @@ class CrTplApplication(FbConfigApplication): cfg_class=CrTplConfiguration, description=desc, initialized=False, ) + self.cfg.strip_unnessecary() + self.initialized = True # ------------------------------------------------------------------------- @@ -371,7 +373,6 @@ class CrTplApplication(FbConfigApplication): Dummy function as main routine. MUST be overwritten by descendant classes. - """ LOG.info(_("Starting {a!r}, version {v!r} ...").format( diff --git a/lib/cr_vmware_tpl/cobbler.py b/lib/cr_vmware_tpl/cobbler.py index 89dbc1b..3736e1d 100644 --- a/lib/cr_vmware_tpl/cobbler.py +++ b/lib/cr_vmware_tpl/cobbler.py @@ -45,7 +45,7 @@ from .config import CrTplConfiguration from .xlate import XLATOR -__version__ = '0.9.3' +__version__ = '0.10.0' LOG = logging.getLogger(__name__) @@ -536,6 +536,11 @@ class Cobbler(BaseHandler): # ------------------------------------------------------------------------- def ensure_profile_ks(self): + ks_template_name = self.cfg.current_distro.ks_template + + LOG.info(_("Using {!r} as a template for the kickstart file.").format( + './templates/' + ks_template_name)) + prefix = 'tmp.' + self.cfg.cobbler_profile + '.' (fh, tmp_ks) = tempfile.mkstemp(prefix=prefix, suffix='.ks', text=True) os.close(fh) @@ -550,7 +555,7 @@ class Cobbler(BaseHandler): loader=jinja2.FileSystemLoader(str(self.base_dir / 'templates')), autoescape=jinja2.select_autoescape(), ) - ks_template = jinja_env.get_template('el-standard.ks') + ks_template = jinja_env.get_template(ks_template_name) ks_content = ks_template.render( distro=self.cfg.current_distro, snippets=snippet_lst) + '\n\n' if self.verbose > 1: @@ -597,7 +602,7 @@ class Cobbler(BaseHandler): profile_vars = self.get_profile_vars(profile) - if self.verbose > 2: + if self.verbose > 1: LOG.debug(_("Got profile variables:") + '\n' + pp(profile_vars)) self._change_profile(profile_vars) @@ -639,6 +644,7 @@ class Cobbler(BaseHandler): profile = self.cfg.cobbler_profile distro = self.cfg.cobbler_distro distro_info = self.cfg.current_distro + status = self.cfg.system_status LOG.debug(_("Checking existing profile {n!r} ({d}) ...").format( n=profile, d=distro_info.description)) @@ -702,6 +708,43 @@ class Cobbler(BaseHandler): args.append('--name-servers-search') args.append(' '.join(self.cfg.cobbler_dns_search)) + ks_meta_ok = True + ks_meta_vars = {} + if 'autoinstall_meta' in profile_vars: + ks_meta_vars = self.xform_ks_meta(profile_vars['autoinstall_meta']) + if 'ROOT_PWD_HASH' not in ks_meta_vars: + LOG.debug(_('Profile ks_meta {!r} is not ok.').format('ROOT_PWD_HASH')) + ks_meta_ok = False + if ('SWAP_SIZE_MB' not in ks_meta_vars or + ks_meta_vars['SWAP_SIZE_MB'] != str(self.cfg.swap_size_mb)): + LOG.debug(_('Profile ks_meta {!r} is not ok.').format('SWAP_SIZE_MB')) + ks_meta_ok = False + if ('SYSTEM_STATUS' not in ks_meta_vars or + ks_meta_vars['SYSTEM_STATUS'] != status): + LOG.debug(_('Profile ks_meta {!r} is not ok.').format('SYSTEM_STATUS')) + ks_meta_ok = False + if ('WS_REL_FILESDIR' not in ks_meta_vars or + ks_meta_vars['WS_REL_FILESDIR'] != str(self.cfg.cobbler_ws_rel_filesdir)): + LOG.debug(_('Profile ks_meta {!r} is not ok.').format('WS_REL_FILESDIR')) + ks_meta_ok = False + if ('COBBLER_URL' not in ks_meta_vars or + ks_meta_vars['COBBLER_URL'] != "http://{}".format(self.cfg.cobbler_host)): + LOG.debug(_('Profile ks_meta {!r} is not ok.').format('COBBLER_URL')) + ks_meta_ok = False + + if not ks_meta_ok: + ks_meta_list = [] + ks_meta_list.append("ROOT_PWD_HASH={}".format(self.cfg.get_root_pwd_hash())) + ks_meta_list.append("SWAP_SIZE_MB={}".format(self.cfg.swap_size_mb)) + ks_meta_list.append("SYSTEM_STATUS={}".format(status)) + ks_meta_list.append("WS_REL_FILESDIR={}".format(self.cfg.cobbler_ws_rel_filesdir)) + ks_meta_list.append("COBBLER_URL=http://{}".format(self.cfg.cobbler_host)) + + ks_meta = ' '.join(ks_meta_list) + + args.append('--autoinstall-meta') + args.append(ks_meta) + if self.verbose: LOG.debug("Args for 'profile edit:\n{}".format(pp(args))) @@ -711,6 +754,10 @@ class Cobbler(BaseHandler): args = ['profile', 'edit', '--name', profile] + args + if self.verbose > 1: + LOG.debug('Arguments for changing profile:\n' + pp(args)) + return + proc = self.exec_cobbler(args) if proc.returncode: @@ -723,6 +770,24 @@ class Cobbler(BaseHandler): rc=proc.returncode, err=err) raise ExpectedCobblerError(msg) + # ------------------------------------------------------------------------- + def xform_ks_meta(self, ks_meta): + + data = {} + + re_ws = re.compile(r'\s+') + re_key_value = re.compile(r'(\S+)=(.*)') + + for token in re_ws.split(ks_meta): + m = re_key_value.match(token) + if m: + data[m.group(1)] = m.group(2) + + if self.verbose > 1: + LOG.debug("Got autoinstall_meta from profile:\n" + pp(data)) + + return data + # ------------------------------------------------------------------------- def add_profile(self): """Creating a new profile.""" @@ -733,9 +798,21 @@ class Cobbler(BaseHandler): distro_info = self.cfg.current_distro comment = "Profile for creating a {} VM.".format(distro_info.description) + status = self.cfg.system_status LOG.debug("Using kickstart file {!r}".format(self.cfg.cobbler_profile_ks)) + ks_meta_list = [] + ks_meta_list.append("ROOT_PWD_HASH={}".format(self.cfg.get_root_pwd_hash())) + ks_meta_list.append("SWAP_SIZE_MB={}".format(self.cfg.swap_size_mb)) + ks_meta_list.append("SYSTEM_STATUS={}".format(status)) + ks_meta_list.append("WS_REL_FILESDIR={}".format(self.cfg.cobbler_ws_rel_filesdir)) + ks_meta_list.append("COBBLER_URL=http://{}".format(self.cfg.cobbler_host)) + + ks_meta = None + if ks_meta_list: + ks_meta = ' '.join(ks_meta_list) + repos = [] if distro_info.repos: repos = distro_info.repos.as_list() @@ -758,6 +835,12 @@ class Cobbler(BaseHandler): args.append(' '.join(repos)) args.append('--comment') args.append(comment) + if ks_meta: + if self.cfg.cobbler_major_version == 3: + args.append('--autoinstall-meta') + else: + args.append('--ksmeta') + args.append(ks_meta) args.append('--virt-cpus') args.append('2') args.append('--virt-file-size') diff --git a/lib/cr_vmware_tpl/config.py b/lib/cr_vmware_tpl/config.py index ccc41d9..0d630a2 100644 --- a/lib/cr_vmware_tpl/config.py +++ b/lib/cr_vmware_tpl/config.py @@ -33,7 +33,7 @@ from . import DEFAULT_CONFIG_DIR, DEFAULT_DISTRO_ARCH, MAX_PORT_NUMBER from .xlate import XLATOR -__version__ = '2.2.1' +__version__ = '2.3.0' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -338,6 +338,9 @@ class LdapConnectionInfo(FbBaseObject): new.admin_filter = value continue + if key.lower() in ['is_admin', 'readonly', 'tier', 'sync-source' ]: + continue + msg = _("Unknown LDAP configuration key {key} found in section {sec!r}.").format( key=key, sec=s_name) LOG.error(msg) @@ -367,6 +370,8 @@ class CobblerDistroInfo(FbGenericBaseObject): self._description = None self._arch = DEFAULT_DISTRO_ARCH self._ks_repo_url = None + self._is_rhel = False + self._ks_template = 'el8-standard.ks' self.packages = [] self.repos = CIStringSet() self.snippets = CIStringSet() @@ -518,6 +523,32 @@ class CobblerDistroInfo(FbGenericBaseObject): self._ks_repo_url = ks_repo_url + # ------------------------------------------------------------------------- + @property + def is_rhel(self): + """Is the currwnt distro a RHEL distro?""" + return self._is_rhel + + @is_rhel.setter + def is_rhel(self, value): + self._is_rhel = to_bool(value) + + # ------------------------------------------------------------------------- + @property + def ks_template(self): + """The filename below templates for generating the final kickstart file.""" + + return getattr(self, '_ks_template', 'el8-standard.ks') + + @ks_template.setter + def ks_template(self, value): + if value is None: + return + template = value.strip() + if template == '': + return + self._ks_template = template + # ------------------------------------------------------------------------- def __repr__(self): """Typecasting into a string for reproduction.""" @@ -529,6 +560,8 @@ class CobblerDistroInfo(FbGenericBaseObject): fields.append("shortname={!r}".format(self._shortname)) fields.append("distro={!r}".format(self.distro)) fields.append("arch={!r}".format(self.arch)) + fields.append("is_rhel={!r}".format(self.is_rhel)) + fields.append("ks_template={!r}".format(self.ks_template)) fields.append("description={!r}".format(self.description)) fields.append("ks_repo_url={!r}".format(self.ks_repo_url)) @@ -549,12 +582,14 @@ class CobblerDistroInfo(FbGenericBaseObject): """ res = super(CobblerDistroInfo, self).as_dict(short=short) - res['name'] = self.name - res['shortname'] = self.shortname - res['distro'] = self.distro res['arch'] = self.arch res['description'] = self.description + res['distro'] = self.distro + res['is_rhel'] = self.is_rhel res['ks_repo_url'] = self.ks_repo_url + res['ks_template'] = self.ks_template + res['name'] = self.name + res['shortname'] = self.shortname return res @@ -609,10 +644,18 @@ class CobblerDistroInfo(FbGenericBaseObject): new.arch = value.strip() continue + if key.lower() == 'is_rhel': + new.is_rhel = value + continue + if key.lower() == 'ks_repo_url' and value.strip() != '': new.ks_repo_url = value.strip() continue + if key.lower() == 'ks_template' and value.strip() != '': + new._ks_template = value.strip() + continue + if key.lower() == 'repos': cls._update_repos(new, value) continue @@ -1155,6 +1198,8 @@ class CrTplConfiguration(BaseMultiConfig): if not distro.description: distro.description = distro_id + LOG.debug(_("Searching for distro with ID {!r} ...").format(self.os_id)) + if self.os_id not in self.cobbler_distros: msg = _("Did not found distro {!r} in configured Cobbler distros.").format(self.os_id) raise CrTplConfigError(msg) @@ -1618,6 +1663,33 @@ class CrTplConfiguration(BaseMultiConfig): if self.verbose > 3: LOG.debug(_("Evaluated Cobbler repositories:") + '\n' + pp(self.cobbler_repos)) + # ------------------------------------------------------------------------- + def strip_unnessecary(self): + """Stripping no more necessary stuff.""" + LOG.debug(_("Stripping no more necessary stuff from configuration ...")) + + if self.verbose > 1: + LOG.debug(_("Stripping {!r} ...").format('cfg.cobbler-distros')) + if 'cobbler-distros' in self.cfg: + del self.cfg['cobbler-distros'] + + if self.verbose > 1: + LOG.debug(_("Stripping {!r} ...").format('cfg.cobbler-repos')) + if 'cobbler-repos' in self.cfg: + del self.cfg['cobbler-repos'] + + if self.verbose > 1: + LOG.debug(_("Stripping {!r} ...").format('cobbler_distros')) + self.cobbler_distros = {} + + if self.verbose > 1: + LOG.debug(_("Stripping {!r} ...").format('cobbler_repos')) + self.cobbler_repos = {} + + if self.verbose > 1: + LOG.debug(_("Stripping {!r} ...").format('configs_raw')) + self.configs_raw = {} + # ============================================================================= if __name__ == "__main__": diff --git a/lib/cr_vmware_tpl/handler.py b/lib/cr_vmware_tpl/handler.py index 2b38635..7d78ef7 100644 --- a/lib/cr_vmware_tpl/handler.py +++ b/lib/cr_vmware_tpl/handler.py @@ -54,7 +54,7 @@ from .cobbler import Cobbler from .xlate import XLATOR -__version__ = '2.3.2' +__version__ = '2.3.3' LOG = logging.getLogger(__name__) TZ = pytz.timezone('Europe/Berlin') @@ -346,6 +346,8 @@ class CrTplHandler(BaseHandler): if self.verbose > 2: LOG.debug(_("Current configuration:") + '\n' + pp(self.cfg.as_dict())) + elif self.verbose > 1: + LOG.debug(_("Current distribution:") + '\n' + pp(self.cfg.current_distro.as_dict())) LOG.debug(_("Starting handling ...")) self.cobbler.get_cobbler_version() @@ -353,6 +355,8 @@ class CrTplHandler(BaseHandler): self.cobbler.ensure_profile_ks() self.create_root_authkeys() self.cobbler.ensure_profile() + return 0 + self.cobbler.ensure_webroot() # self.cobbler.ensure_root_authkeys(self.auth_keys_file) self.cobbler.ensure_rsyslog_cfg_files() diff --git a/templates/el-standard.ks b/templates/el7-standard.ks similarity index 71% rename from templates/el-standard.ks rename to templates/el7-standard.ks index b460996..6b08003 100644 --- a/templates/el-standard.ks +++ b/templates/el7-standard.ks @@ -15,22 +15,31 @@ sshpw --username=inst testtest --plaintext # Root install-password rootpw --iscrypted ${ROOT_PWD_HASH} + # System authorization information auth --useshadow --passalgo=sha512 + # Use text mode install text + # System keyboard -keyboard de +keyboard de --vckeymap=de-deadacute + # System language lang en_US + # SELinux configuration selinux --permissiv + # Do not configure the X Window System skipx + # Installation logging level logging --level=debug + # Reboot after installation reboot + # System timezone timezone Europe/Berlin @@ -44,17 +53,17 @@ zerombr bootloader --location=mbr --append="net.ifnames=0 biosdevname=0" # Partition clearing information -clearpart --all --drive=sda +clearpart --all --drive=sda --initlabel # Disk partitioning information part /boot --fstype ext4 --size=512 --ondisk=sda -part swap --size=${SWAP_SIZE_MB} --ondisk=sda part pv.01 --size=1 --grow --ondisk=sda volgroup vgroot pv.01 logvol / --vgname=vgroot --name=root --size=6144 +logvol swap --vgname=vgroot --name=swap --fstype=swap --size=${SWAP_SIZE_MB} logvol /home --vgname=vgroot --name=home --size=1024 logvol /var --vgname=vgroot --name=var --size=4096 --grow -logvol /var/log --vgname=vgroot --name=log --size=2048 +logvol /var/log --vgname=vgroot --name=log --size=3072 ########################################## # Packages @@ -65,6 +74,37 @@ logvol /var/log --vgname=vgroot --name=log --size=2048 {%- endfor %} %end +########################################## +# Pre tasks +%pre --interpreter=/bin/bash --log=/var/log/ks-pre.log +#raw +echo "[$( date --rfc-3339=seconds )]: Let's launch the missle ..." +echo +if grep '^nameserver' /etc/resolv.conf >/dev/null ; then + echo "Nameservers are defined in /etc/resolv.conf:" + grep '^nameserver' /etc/resolv.conf +else + echo "Adding nameservers 93.188.109.12, 93.188.104.82 and 217.66.52.10 to /etc/resolv.conf ..." + echo "nameserver 93.188.109.12" >>/etc/resolv.conf + echo "nameserver 93.188.104.82" >>/etc/resolv.conf + echo "nameserver 217.66.52.10" >>/etc/resolv.conf +fi + +echo +echo "Used /etc/resolv.conf:" +cat /etc/resolv.conf + +#end raw +%end + +########################################## +# Pre installation tasks +%pre-install --interpreter=/bin/bash --log=/var/log/ks-pre-install.log +#raw +echo "[$( date --rfc-3339=seconds )]: Pre installation tasks ..." +#end raw +%end + ########################################## # Post installation tasks in chroot env @@ -163,3 +203,24 @@ $SNIPPET($this_snippet) # Seems to be finished %end + +########################################## +# Second post install section without chroot + +%post --nochroot +#raw + +mkdir -pv /mnt/sysroot/var/log/anaconda + +for f in /var/log/ks-pre.log /var/log/ks-pre-install.log /var/log/anaconda/post-install.log ; do + if test -f "${f}" : then + cp -pv "${f}" /mnt/sysroot/var/log/anaconda/ + else + echo "File '${f}' not found!" + fi +done + +#end raw +%end + +# Last line diff --git a/templates/el8-standard.ks b/templates/el8-standard.ks new file mode 100644 index 0000000..0e8bddb --- /dev/null +++ b/templates/el8-standard.ks @@ -0,0 +1,226 @@ +###################################################################################### +# Provisioning-Installation of {{ distro.description }} +###################################################################################### +# +# Standard Pixelpark Installation of {{ distro.name }} templates. +# + +# Firewall configuration +firewall --disabled + +# Use network installation from cobbler host +url --url="{{ distro.ks_repo_url }}" --noverifyssl + +sshpw --username=inst testtest --plaintext + +# Root install-password +rootpw --iscrypted ${ROOT_PWD_HASH} + +# System authorization information +authselect minimal with-mkhomedir with-pwhistory without-nullok + +# Use text mode install +text + +# System keyboard +keyboard de --vckeymap=de-deadacute + +# System language +lang en_US + +# SELinux configuration +selinux --permissiv + +# Do not configure the X Window System +skipx + +# Installation logging level +logging --level=debug + +# Reboot after installation +reboot + +# System timezone +timezone Europe/Berlin + +########################################### +# Partitioning and Disk + +# Clear the Master Boot Record +zerombr + +# System bootloader configuration +bootloader --location=mbr --append="net.ifnames=0 biosdevname=0" + +# Partition clearing information +clearpart --all --drive=sda + +# Disk partitioning information +part /boot --fstype ext4 --size=512 --ondisk=sda +part pv.01 --size=1 --grow --ondisk=sda +volgroup vgroot pv.01 +logvol / --vgname=vgroot --name=root --size=6144 +logvol swap --vgname=vgroot --name=swap --fstype=swap --size=${SWAP_SIZE_MB} +logvol /home --vgname=vgroot --name=home --size=1024 +logvol /var --vgname=vgroot --name=var --size=4096 --grow +logvol /var/log --vgname=vgroot --name=log --size=3072 + +########################################## +# Packages + +%packages +{%- for package in distro.packages %} +{{ package }} +{%- endfor %} +%end + +########################################## +# Pre tasks +%pre --interpreter=/bin/bash --log=/var/log/ks-pre.log +#raw +echo "[$( date --rfc-3339=seconds )]: Let's launch the missle ..." +echo +if grep '^nameserver' /etc/resolv.conf >/dev/null ; then + echo "Nameservers are defined in /etc/resolv.conf:" + grep '^nameserver' /etc/resolv.conf +else + echo "Adding nameservers 93.188.109.12, 93.188.104.82 and 217.66.52.10 to /etc/resolv.conf ..." + echo "nameserver 93.188.109.12" >>/etc/resolv.conf + echo "nameserver 93.188.104.82" >>/etc/resolv.conf + echo "nameserver 217.66.52.10" >>/etc/resolv.conf +fi + +echo +echo "Used /etc/resolv.conf:" +cat /etc/resolv.conf + +#end raw +%end + +########################################## +# Pre installation tasks +%pre-install --interpreter=/bin/bash --log=/var/log/ks-pre-install.log +#raw +echo "[$( date --rfc-3339=seconds )]: Pre installation tasks ..." +#end raw +%end + +########################################## +# Post installation tasks in chroot env + +%post --interpreter=/usr/bin/bash + +### output to console +mkdir -p "/var/log/anaconda" +clear +POST_LOG="/var/log/anaconda/post-install.log" +exec < /dev/console &> >(tee -a "$POST_LOG") + +###################################################################################### +# Installation of pixelpark standard applications +###################################################################################### + + +### debug +# set -x + +echo "cobbler profile = $profile_name" + +echo +echo "IP interfaces" +ip link show + +echo +echo "IP addresses" +ip address show + +echo +echo "IPv4 routes" +ip route list + +echo +echo "IPv6 routes" +ip -6 route list + +echo +echo "/etc/resolv.conf" +cat /etc/resolv.conf + +if [[ -d "/etc/yum.repos.d" ]] ; then + + echo + echo "/etc/yum.repos.d/" + ls -lA /etc/yum.repos.d + + for repo_file in /etc/yum.repos.d/*.repo ; do + if [[ -f "${repo_file}" ]] ; then + echo + echo "${repo_file}" + echo '---' + cat "${repo_file}" + echo '---' + fi + done + +fi + + +### remove unnecessary directory +rm -rf /var/var + +export hostname="$hostname" +export system_name="$system_name" +export gateway="$gateway" +export mgmt_interface="eth0" +export ip_address_eth0="$ip_address_eth0" +export mac_address_eth0="$mac_address_eth0" +export system_status="${SYSTEM_STATUS}" +export ws_rel_filesdir="${WS_REL_FILESDIR}" +export cobbler_url="${COBBLER_URL}" + +echo +echo "hostname: '$hostname'" +echo "system_name: '$system_name'" +echo "gateway: '$gateway'" +echo "Management interface: '${mgmt_interface}'" +echo "ip_address_eth0: '$ip_address_eth0'" +echo "mac_address_eth0: '$mac_address_eth0'" +echo "System status: '${system_status}'" +echo "Cobbler URL: '${cobbler_url}'" + +############################################################################### +# Performing snippets + +{%- for snippet in snippets %} + +#set $this_snippet= "per_status/" + $SYSTEM_STATUS + "/{{ snippet }}" +echo +echo "Using snippet $this_snippet" +$SNIPPET($this_snippet) +{%- endfor %} + +# ########################### +# Seems to be finished + +%end + +########################################## +# Second post install section without chroot + +%post --nochroot +#raw + +mkdir -pv /mnt/sysroot/var/log/anaconda + +for f in /var/log/ks-pre.log /var/log/ks-pre-install.log /var/log/anaconda/post-install.log ; do + if test -f "${f}" : then + cp -pv "${f}" /mnt/sysroot/var/log/anaconda/ + else + echo "File '${f}' not found!" + fi +done + +#end raw +%end + +# Last line diff --git a/templates/el9-standard.ks b/templates/el9-standard.ks new file mode 100644 index 0000000..c462933 --- /dev/null +++ b/templates/el9-standard.ks @@ -0,0 +1,255 @@ +###################################################################################### +# Provisioning-Installation of {{ distro.description }} +###################################################################################### +# +# Standard Pixelpark Installation of {{ distro.name }} templates. +# + +# Firewall configuration +firewall --disabled + +# Use network installation from cobbler host +url --url="{{ distro.ks_repo_url }}" --noverifyssl + +sshpw --username=inst testtest --plaintext + +# Root install-password +rootpw --iscrypted ${ROOT_PWD_HASH} + +# System authorization information +authselect minimal with-mkhomedir with-pwhistory without-nullok + +# Use text mode install +text + +# System keyboard +keyboard --vckeymap=de-deadacute + +# System language +lang en_US + +# SELinux configuration +selinux --permissiv + +# Do not configure the X Window System +skipx + +# Installation logging level +logging --level=debug + +# Reboot after installation +reboot + +# System timezone +timezone Europe/Berlin + +########################################### +# Partitioning and Disk + +# Clear the Master Boot Record +zerombr + +# System bootloader configuration +bootloader --location=mbr --append="net.ifnames=0 biosdevname=0 crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M" + +# Partition clearing information +clearpart --all --drive=sda --initlabel + +# Disk partitioning information +part /boot --fstype ext4 --size=512 --ondisk=sda --asprimary +part pv.01 --size=1 --grow --ondisk=sda +volgroup vgroot pv.01 +logvol / --vgname=vgroot --name=root --fstype=xfs --size=6144 +logvol swap --vgname=vgroot --name=swap --fstype=swap --size=${SWAP_SIZE_MB} +logvol /home --vgname=vgroot --name=home --fstype=xfs --size=1024 +logvol /var --vgname=vgroot --name=var --fstype=xfs --size=4096 --grow +logvol /var/log --vgname=vgroot --name=log --fstype=xfs --size=3072 + +########################################## +# Packages + +%packages +{%- for package in distro.packages %} +{{ package }} +{%- endfor %} +%end + +########################################## +# Pre tasks +%pre --interpreter=/bin/bash --log=/var/log/ks-pre.log +#raw +echo "[$( date --rfc-3339=seconds )]: Let's launch the missle ..." +echo +if grep '^nameserver' /etc/resolv.conf >/dev/null ; then + echo "Nameservers are defined in /etc/resolv.conf:" + grep '^nameserver' /etc/resolv.conf +else + echo "Adding nameservers 93.188.109.12, 93.188.104.82 and 217.66.52.10 to /etc/resolv.conf ..." + echo "nameserver 93.188.109.12" >>/etc/resolv.conf + echo "nameserver 93.188.104.82" >>/etc/resolv.conf + echo "nameserver 217.66.52.10" >>/etc/resolv.conf +fi + +echo +echo "Used /etc/resolv.conf:" +cat /etc/resolv.conf + +#end raw +%end + +########################################## +# Pre installation tasks +%pre-install --interpreter=/bin/bash --log=/var/log/ks-pre-install.log +#raw +echo "[$( date --rfc-3339=seconds )]: Pre installation tasks ..." +#end raw +%end + +########################################## +# Post installation tasks in chroot env + +%post --interpreter=/usr/bin/bash + +### output to console +mkdir -p -v "/var/log/anaconda" +clear +POST_LOG="/var/log/anaconda/post-install.log" +exec < /dev/console &> >(tee -a "$POST_LOG") + +###################################################################################### +# Installation of pixelpark standard applications +###################################################################################### + + +### debug +# set -x + +echo "cobbler profile = $profile_name" + +echo +echo "IP interfaces" +ip link show + +echo +echo "IP addresses" +ip address show + +echo +echo "IPv4 routes" +ip route list + +echo +echo "IPv6 routes" +ip -6 route list + +echo +echo "/etc/resolv.conf" +cat /etc/resolv.conf + +if [[ -d "/etc/yum.repos.d" ]] ; then + + echo + echo "/etc/yum.repos.d/" + ls -lA /etc/yum.repos.d + + for repo_file in /etc/yum.repos.d/*.repo ; do + if [[ -f "${repo_file}" ]] ; then + echo + echo "${repo_file}" + echo '---' + cat "${repo_file}" + echo '---' + fi + done + +fi + + +### remove unnecessary directory +rm -rf /var/var + +export hostname="$hostname" +export system_name="$system_name" +export gateway="$gateway" +export mgmt_interface="eth0" +export ip_address_eth0="$ip_address_eth0" +export mac_address_eth0="$mac_address_eth0" +export system_status="${SYSTEM_STATUS}" +export ws_rel_filesdir="${WS_REL_FILESDIR}" +export cobbler_url="${COBBLER_URL}" +{% if distro.is_rhel %} +export rhsm_user="${RHSM_USER}" +export rhsm_pwd="${RHSM_PWD}" +export rhsm_system_id="${RHSM_SYSTEM_ID}" +export rhsm_registred='' + +export redhat_repo_server='https://cdn.redhat.com' +if [[ -n "${REDHAT_REPO_SERVER}" ]] ; then + redhat_repo_server="${REDHAT_REPO_SERVER}" +fi + +export redhat_repo_path_prefix='/content' +if [[ -n "${REDHAT_REPO_PATH_PREFIX}" ]] ; then + redhat_repo_path_prefix="${REDHAT_REPO_PATH_PREFIX}" +fi + +export redhat_gpg_key='file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release' +if [[ -n "${REDHAT_GPG_KEY}" ]] ; then + redhat_gpg_key="${REDHAT_GPG_KEY}" +fi + +{% endif %} +echo +echo "hostname: '$hostname'" +echo "system_name: '$system_name'" +echo "gateway: '$gateway'" +echo "Management interface: '${mgmt_interface}'" +echo "ip_address_eth0: '$ip_address_eth0'" +echo "mac_address_eth0: '$mac_address_eth0'" +echo "System status: '${system_status}'" +echo "Cobbler URL: '${cobbler_url}'" +{% if distro.is_rhel %} +echo +echo "RedHat SubscriptionManager User: '${rhsm_user}'" +echo "RedHat SubscriptionManager System ID: '${rhsm_system_id}'" +echo "RedHat repository server: '${redhat_repo_server}'" +echo "RedHat repository path prefix: '${redhat_repo_path_prefix}'" +echo "RedHat GPK key: '${redhat_gpg_key}'" +{% endif %} + +############################################################################### +# Performing snippets + +{%- for snippet in snippets %} + +#set $this_snippet= "per_status/" + $SYSTEM_STATUS + "/{{ snippet }}" +echo +echo "Using snippet $this_snippet" +$SNIPPET($this_snippet) +{%- endfor %} + +# ########################### +# Seems to be finished + +%end + +########################################## +# Second post install section without chroot + +%post --nochroot +#raw + +mkdir -pv /mnt/sysroot/var/log/anaconda + +for f in /var/log/ks-pre.log /var/log/ks-pre-install.log /var/log/anaconda/post-install.log ; do + if test -f "${f}" : then + cp -pv "${f}" /mnt/sysroot/var/log/anaconda/ + else + echo "File '${f}' not found!" + fi +done + +#end raw +%end + +# Last line -- 2.39.5