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:
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):
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
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