From 6a047d00989c91c301d362d1606163f89a60c26d Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Mon, 11 Apr 2022 15:35:23 +0200 Subject: [PATCH] Revert "Merge branch 'rwaffen_remove_gen_types' into 'master'" This reverts merge request !3 --- lib/webhooks/r10k.py | 46 ++++++++++++++++++++++++++++++++++++++++++++ update_puppet5_env | 14 +++++++++++--- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/lib/webhooks/r10k.py b/lib/webhooks/r10k.py index 7ba30b1..77dac4d 100644 --- a/lib/webhooks/r10k.py +++ b/lib/webhooks/r10k.py @@ -225,6 +225,11 @@ class R10kHookApp(BaseHookApp): LOG.warn(_("Executing {!r} was not successful.").format(str(self.r10k_bin))) return + if not self.generate_puppet_types(): + what = '{c} generate types --environment {e}'.format(c=self.puppet_bin, e=self.ref) + LOG.warn(_("{!r} was not successful.").format(what)) + return + return self.del_env_cache() finally: @@ -300,6 +305,47 @@ class R10kHookApp(BaseHookApp): self.print_out(msg) return + # ------------------------------------------------------------------------- + def generate_puppet_types(self): + """Generates definitions for custom resource types using Puppet code + for the given environment.""" + + LOG.info(_("Generating Puppet types for environment {e!r} on {h!r}.").format( + e=self.ref, h=self.puppetmaster_host)) + + res = True + + cmd = [ + str(self.puppet_bin), 'generate', 'types', + '--environment', self.ref, + '--color', 'false', ] + + if self.verbose > 1: + cmd.append('--verbose') + if self.verbose > 3: + cmd.append('--debug') + + proc = self.handler.call(cmd, sudo=self.do_sudo, quiet=False) + + if proc.stdout: + msg = _("Output:") + '\n' + proc.stdout + self.print_out(msg) + else: + LOG.debug(_("No output.")) + + if proc.stderr: + cmd_str = ' '.join(map(lambda x: pipes.quote(x), proc.args)) + msg = _("Error messages on {c!r}:\n{e}").format(c=cmd_str, e=proc.stderr) + msg_rc = _("Returncode was {}.").format(proc.returncode) + self.print_out(msg) + if proc.returncode: + self.print_out(msg_rc) + self.error_data.append(msg) + self.error_data.append(msg_rc) + res = False + + return res + # ------------------------------------------------------------------------- def exec_r10k(self): diff --git a/update_puppet5_env b/update_puppet5_env index c71910c..d5dc73a 100755 --- a/update_puppet5_env +++ b/update_puppet5_env @@ -4,10 +4,14 @@ set -e set -u PUPPET_CONF="/etc/puppetlabs/puppet/puppet.conf" -CERTNAME=$(/opt/puppetlabs/bin/puppet config print certname --section agent) - +CERTNAME=$(cat /etc/puppetlabs/puppet/puppet.conf | \ + grep -P -v '^\s*#' | \ + grep -P -v '^\s*$' | \ + grep -P -o '^\s*certname(\s|=).*' | \ + awk -F'=' '{print $2}' | \ + sed -e 's/^[ ]*//' -e 's/[ ]*$//') if [[ -z "${CERTNAME}" ]] ; then - CERTNAME=$(/opt/puppetlabs/bin/facter networking.fqdn) + CERTNAME=$(hostname -f) fi echo @@ -54,6 +58,10 @@ for env in ${envs} ; do echo -e "\nEnvironment-Verzeichnis '${env_dir}' existiert nicht." >&2 fi + cmd="/opt/puppetlabs/puppet/bin/puppet generate types --environment \"${env}\"" + echo "${cmd}" + eval ${cmd} + echo echo "Finished environment '${env}'." sleep 1 -- 2.39.5