--- /dev/null
+#!/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