]> Frank Brehm's Git Trees - pixelpark/puppetmaster-webhooks.git/commitdiff
Adding update_puppet5_env
authorFrank Brehm <frank.brehm@pixelpark.com>
Mon, 27 Nov 2017 13:46:44 +0000 (14:46 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Mon, 27 Nov 2017 13:46:44 +0000 (14:46 +0100)
update_puppet5_env [new file with mode: 0755]

diff --git a/update_puppet5_env b/update_puppet5_env
new file mode 100755 (executable)
index 0000000..81969c0
--- /dev/null
@@ -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