From 119a45308f3cdb034ee9cd118807641fc12d26a1 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 28 Jun 2022 15:09:34 +0200 Subject: [PATCH] Start integrating snippets --- etc/cobbler-distros.yaml.default | 15 +++++++++++++++ lib/cr_vmware_tpl/cobbler.py | 9 +++++++-- templates/el-standard.ks | 14 ++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/etc/cobbler-distros.yaml.default b/etc/cobbler-distros.yaml.default index 14e0d72..478e8c5 100644 --- a/etc/cobbler-distros.yaml.default +++ b/etc/cobbler-distros.yaml.default @@ -53,6 +53,9 @@ cobbler-distros: - 'pixelpark-el8-x86_64' - 'monitoring-noarch' - 'prometheus-el8-x86_64' + snippets: + - 'tpl.001.basics.sh' + - 'tpl.010.authkeys.sh' centos-7: distro: 'CentOS-7.9-x86_64' description: 'CentOS 7 x86_64' @@ -101,6 +104,9 @@ cobbler-distros: - '-mysql-community*' - '-nfs*' - '-rpcbind' + snippets: + - 'tpl.001.basics.sh' + - 'tpl.010.authkeys.sh' centos-stream-8: distro: 'CentOS-Stream-8-x86_64' description: 'CentOS Stream 8 x86_64' @@ -154,6 +160,9 @@ cobbler-distros: - '-abrt*' - '-nfs*' - '-rpcbind' + snippets: + - 'tpl.001.basics.sh' + - 'tpl.010.authkeys.sh' oel-7: distro: 'Oracle-Linux-7.9-x86_64' description: 'Oracle Enterprise Linux 7 x86_64' @@ -205,6 +214,9 @@ cobbler-distros: - '-nfs*' - '-rpcbind' - '-*uek*' + snippets: + - 'tpl.001.basics.sh' + - 'tpl.010.authkeys.sh' rocky-8: distro: 'Rocky-8.6-x86_64' description: 'Rocky Linux 8 x86_64' @@ -258,6 +270,9 @@ cobbler-distros: - '-abrt*' - '-nfs*' - '-rpcbind' + snippets: + - 'tpl.001.basics.sh' + - 'tpl.010.authkeys.sh' cobbler-repos: almalinux-8-x86_64-appstream: diff --git a/lib/cr_vmware_tpl/cobbler.py b/lib/cr_vmware_tpl/cobbler.py index 4cb4c61..e3cb7b4 100644 --- a/lib/cr_vmware_tpl/cobbler.py +++ b/lib/cr_vmware_tpl/cobbler.py @@ -46,7 +46,7 @@ from .config import CrTplConfiguration from .xlate import XLATOR -__version__ = '0.8.4' +__version__ = '0.8.5' LOG = logging.getLogger(__name__) @@ -523,12 +523,17 @@ class Cobbler(BaseHandler): self.local_ks_file = Path(tmp_ks) LOG.debug(_("Using temporary kickstart file {!r}.").format(tmp_ks)) + snippet_lst = [] + for snippet in sorted(self.cfg.current_distro.snippets.values(), key=str.lower): + snippet_lst.append(snippet) + jinja_env = jinja2.Environment( loader=jinja2.FileSystemLoader(str(self.base_dir / 'templates')), autoescape=jinja2.select_autoescape(), ) ks_template = jinja_env.get_template('el-standard.ks') - ks_content = ks_template.render(distro=self.cfg.current_distro) + '\n\n' + ks_content = ks_template.render( + distro=self.cfg.current_distro, snippets=snippet_lst) + '\n\n' if self.verbose > 1: LOG.debug(_("Generated kickstart file content:") + '\n' + ks_content) diff --git a/templates/el-standard.ks b/templates/el-standard.ks index f3ec695..1b25d01 100644 --- a/templates/el-standard.ks +++ b/templates/el-standard.ks @@ -146,4 +146,18 @@ echo "ip_address_eth0: '$ip_address_eth0'" echo "mac_address_eth0: '$mac_address_eth0'" echo "System status: '${system_status}'" +############################################################################### +# 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 -- 2.39.5