From b000dc913301dc1692977bbe37e6cbb2cdeffa41 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Mon, 27 Nov 2017 14:46:44 +0100 Subject: [PATCH] Adding update_puppet5_env --- update_puppet5_env | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 update_puppet5_env diff --git a/update_puppet5_env b/update_puppet5_env new file mode 100755 index 0000000..81969c0 --- /dev/null +++ b/update_puppet5_env @@ -0,0 +1,67 @@ +#!/bin/bash + +set -e +set -u + +PUPPET_CONF="/etc/puppetlabs/puppet/puppet.conf" +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=$(hostname -f) +fi + +echo +echo "###########################################" +echo "Current node: '${CERTNAME}'" +echo + +envs="apache_header_fix icinga2_5 development test production" +if [[ "$#" != "0" ]] ; then + envs="$*" +fi + +for env in ${envs} ; do + + env_dir="/etc/puppetlabs/code/environments/${env}" + + echo + echo "###########################################" + echo "Performing environment '${env}' ..." + echo "###########################################" + echo + + + cmd="/opt/puppetlabs/puppet/bin/r10k deploy environment \"${env}\" -v -p" + echo "${cmd}" + eval ${cmd} + + + if [[ -d "${env_dir}" ]] ; then + echo + sleep 1 + + cmd="/usr/bin/curl -i" + cmd+=" --cert /etc/puppetlabs/puppet/ssl/certs/${CERTNAME}.pem" + cmd+=" --key /etc/puppetlabs/puppet/ssl/private_keys/${CERTNAME}.pem" + cmd+=" --cacert /etc/puppetlabs/puppet/ssl/certs/ca.pem" + cmd+=" -X DELETE" + cmd+=" \"https://${CERTNAME}:8140/puppet-admin-api/v1/environment-cache?environment=${env}\"" + + echo "${cmd}" + eval ${cmd} + + else + echo -e "\nEnvironment-Verzeichnis '${env_dir}' existiert nicht." >&2 + fi + + echo + echo "Finished environment '${env}'." + sleep 1 + +done + +# vim: ts=4 et list -- 2.39.5