aboutsummaryrefslogtreecommitdiff
path: root/bin/deploy
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2020-10-01 15:02:47 -0300
committerSilvio Rhatto <rhatto@riseup.net>2020-10-01 15:02:47 -0300
commitc212514035cffd38acbfac1413064937b28685b6 (patch)
treea043a9c3caac740cf61313d04d9d84280a44f30f /bin/deploy
downloadsemanticscuttle-c212514035cffd38acbfac1413064937b28685b6.tar.gz
semanticscuttle-c212514035cffd38acbfac1413064937b28685b6.tar.bz2
Squashed 'puppet/' content from commit eb5ecc4
git-subtree-dir: puppet git-subtree-split: eb5ecc4fcad6bd4f75e38683ae12a8dba4382c0b
Diffstat (limited to 'bin/deploy')
-rwxr-xr-xbin/deploy80
1 files changed, 80 insertions, 0 deletions
diff --git a/bin/deploy b/bin/deploy
new file mode 100755
index 0000000..f23bc42
--- /dev/null
+++ b/bin/deploy
@@ -0,0 +1,80 @@
+#!/bin/bash
+#
+# Deploy configuration using puppet.
+#
+
+# Parameters
+DIRNAME="`dirname $0`"
+BASEDIR="$DIRNAME/.."
+
+# Install dependencies
+source $DIRNAME/dependencies
+
+# Determine hostname
+#if [ ! -z "$1" ]; then
+# FQDN="$1"
+#else
+# FQDN="`cat /etc/hostname`"
+#fi
+#FQDN="`facter fqdn`"
+FQDN="`cat /etc/hostname`"
+
+# Set manifest
+PUPPET_MANIFEST="$BASEDIR/manifests/nodes/$FQDN.pp"
+if [ ! -e "$PUPPET_MANIFEST" ]; then
+ PUPPET_MANIFEST="$BASEDIR/manifests/nodes/default.pp"
+fi
+
+# Check manifest
+if [ ! -e "$PUPPET_MANIFEST" ]; then
+ echo "No manifest found for $FQDN"
+ exit 1
+fi
+
+# Ensure additional dependencies are installed.
+for package in $DEPLOY_DEPENDENCIES; do
+ provision_package $package
+done
+
+# Parameters that needs dependencies installed
+DIST="`facter lsbdistcodename`"
+
+# Apply patches
+if [ -d "$BASEDIR/puppet/files/patches/$DIST" ]; then
+ (
+ # Patches should be generated relativelly to the root folder
+ cd /
+
+ # Only apply if needed
+ # Thanks https://unix.stackexchange.com/questions/55780/check-if-a-file-or-folder-has-been-patched-already
+ for patch in `ls $BASEDIR/puppet/files/patches/$DIST`; do
+ patch -p0 -N --dry-run --silent < $BASEDIR/puppet/files/patches/$DIST/$patch &> /dev/null
+ # If the patch has not been applied then the $? which is the exit status
+ # for last command would have a success status code = 0
+ if [ "$?" == "0" ]; then
+ # Apply the patch
+ patch -p0 -N < $BASEDIR/puppet/files/patches/$DIST/$patch
+ fi
+ done
+ )
+fi
+
+# Check for Puppetfile
+if [ -e "$BASEDIR/Puppetfile" ]; then
+ if which r10k &> /dev/null; then
+ ( cd $BASEDIR && $SUDO r10k puppetfile install -v )
+ elif which librarian-puppet &> /dev/null; then
+ ( cd $BASEDIR && $SUDO librarian-puppet install )
+ fi
+fi
+
+# Setup facts
+ROLE="`hydractl yaml-param nodo::role $BASEDIR/config/node/$FQDN.yaml default`"
+LOCATION="`hydractl yaml-param nodo::location $BASEDIR/config/node/$FQDN.yaml default`"
+$SUDO mkdir -p /etc/facter/facts.d
+$SUDO echo "role=$ROLE" | $SUDO tee /etc/facter/facts.d/role.txt > /dev/null
+$SUDO echo "location=$LOCATION" | $SUDO tee /etc/facter/facts.d/location.txt > /dev/null
+
+# Run puppet apply
+PUPPET_OPTS="--confdir=$BASEDIR --modulepath=$BASEDIR/modules"
+LC_ALL=C $SUDO puppet apply $PUPPET_OPTS $PUPPET_MANIFEST