aboutsummaryrefslogtreecommitdiff
path: root/puppet/bin
diff options
context:
space:
mode:
Diffstat (limited to 'puppet/bin')
-rwxr-xr-xpuppet/bin/copymodules37
-rwxr-xr-xpuppet/bin/dependencies45
-rwxr-xr-xpuppet/bin/deploy80
-rwxr-xr-xpuppet/bin/mrconfig28
-rwxr-xr-xpuppet/bin/post-receive17
-rwxr-xr-xpuppet/bin/provision30
-rwxr-xr-xpuppet/bin/submodules38
-rwxr-xr-xpuppet/bin/subtrees48
-rwxr-xr-xpuppet/bin/symlinks37
-rwxr-xr-xpuppet/bin/syncmodules37
10 files changed, 397 insertions, 0 deletions
diff --git a/puppet/bin/copymodules b/puppet/bin/copymodules
new file mode 100755
index 0000000..ab5b405
--- /dev/null
+++ b/puppet/bin/copymodules
@@ -0,0 +1,37 @@
+#!/bin/bash
+#
+# Setup symlinks.
+#
+
+# Parameters
+BASENAME="`basename $0`"
+MODULES="$1"
+
+# Check parameters
+if [ -z "$MODULES" ]; then
+ echo "Usage: $BASENAME <submodules-folder>"
+ exit 1
+elif [ ! -e "$MODULES" ]; then
+ echo "Not found: $MODULES"
+fi
+
+# Set puppet folder
+if [ -d "puppet" ]; then
+ PUPPET_FOLDER="puppet"
+else
+ PUPPET_FOLDER="."
+fi
+
+# Add module symlinks using absolute folders
+for module in `ls $MODULES`; do
+ if [ "$module" == "bootstrap" ]; then
+ continue
+ fi
+
+ if echo "$module" | grep -q "^site_"; then
+ continue
+ fi
+
+ path="`cd $MODULES/$module && pwd`"
+ ( cd $PUPPET_FOLDER/modules &> /dev/null && cp -r $path . )
+done
diff --git a/puppet/bin/dependencies b/puppet/bin/dependencies
new file mode 100755
index 0000000..3a47a8e
--- /dev/null
+++ b/puppet/bin/dependencies
@@ -0,0 +1,45 @@
+#!/bin/bash
+#
+# Puppet bootstrap dependencies.
+#
+
+# Parameters
+BASENAME="`basename $0`"
+DEPLOY_DEPENDENCIES="rsync puppet-common hiera-eyaml r10k"
+DEVELOP_DEPENDENCIES="git mr whois hiera-eyaml"
+
+# Additional wheezy dependencies if not using puppet-common from wheezy-backports
+#if [ "`head -c 1 /etc/debian_version`" == '7' ]; then
+# DEPLOY_DEPENDENCIES="$DEPLOY_DEPENDENCIES ruby-hiera-puppet"
+#fi
+
+# Set sudo config
+if [ "`whoami`" != 'root' ]; then
+ SUDO="sudo"
+
+ if ! sudo -n true; then
+ echo "Please set passwordless sudo."
+ exit 1
+ fi
+fi
+
+# Install a package, thanks to the Hydra Suite.
+function provision_package {
+ if [ -z "$1" ]; then
+ return
+ fi
+
+ dpkg -s $1 &> /dev/null
+
+ if [ "$?" == "1" ]; then
+ echo "Installing package $1..."
+ DEBIAN_FRONTEND=noninteractive $SUDO apt-get install $1 -y
+ fi
+}
+
+# Ensure basic packages are installed.
+if [ "$BASENAME" == "dependencies" ]; then
+ for package in $DEVELOP_DEPENDENCIES; do
+ provision_package $package
+ done
+fi
diff --git a/puppet/bin/deploy b/puppet/bin/deploy
new file mode 100755
index 0000000..f23bc42
--- /dev/null
+++ b/puppet/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
diff --git a/puppet/bin/mrconfig b/puppet/bin/mrconfig
new file mode 100755
index 0000000..41be968
--- /dev/null
+++ b/puppet/bin/mrconfig
@@ -0,0 +1,28 @@
+#!/bin/bash
+#
+# Build a mrconfig for the needed modules.
+#
+
+# Parameters
+GIT="git.fluxo.info"
+URL="https://$GIT/projects.list"
+CWD="`pwd`"
+WORK="`dirname $0`/.."
+
+# Create a new config
+cd $WORK
+rm -f $WORK/.mrconfig
+touch $WORK/.mrconfig
+
+# Fetch repository list and update mrconfig
+curl --stderr - $URL | grep "^puppet-" | cut -d ' ' -f 1 | sed -e 's/\.git$//' | while read module; do
+ folder="`echo $module | sed -e 's/^puppet-//'`"
+
+ if [ "$folder" != "bootstrap" ]; then
+ echo "Processing $folder..."
+ mr config puppet/modules/$folder checkout="git clone https://$GIT/$module $folder"
+ fi
+done
+
+# Teardown
+cd $CWD
diff --git a/puppet/bin/post-receive b/puppet/bin/post-receive
new file mode 100755
index 0000000..e6baa07
--- /dev/null
+++ b/puppet/bin/post-receive
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+cd ..
+unset GIT_DIR
+
+if [ -d ".git/annex" ]; then
+ git annex sync
+else
+ #git reset HEAD
+ git checkout -f
+fi
+
+git submodule sync --recursive
+git submodule update --init --recursive
+
+cd -
+exec git update-server-info
diff --git a/puppet/bin/provision b/puppet/bin/provision
new file mode 100755
index 0000000..99cb862
--- /dev/null
+++ b/puppet/bin/provision
@@ -0,0 +1,30 @@
+#!/bin/bash
+#
+# Simple shell provisioner for Vagrant instances.
+#
+
+# Parameters
+DIRNAME="`dirname $0`"
+
+# Load dependencies
+source $DIRNAME/dependencies
+
+# Ensure the system is updated.
+$SUDO apt-get update && DEBIAN_FRONTEND=noninteractive $SUDO apt-get dist-upgrade -y && $SUDO apt-get autoremove -y && $SUDO apt-get clean
+
+# Ensure additional dependencies are installed.
+for package in $DEPLOY_DEPENDENCIES; do
+ provision_package $package
+done
+
+# Link hiera configuration if needed.
+if [ ! -h "/etc/puppet/hiera.yaml" ]; then
+ $SUDO rm -f /etc/puppet/hiera.yaml
+ $SUDO ln -s $DIRNAME/../config/hiera.yaml /etc/puppet/hiera.yaml
+fi
+
+# Link puppet configuration if needed.
+if [ ! -h "/etc/puppet/puppet.conf" ] && [ -e "$DIRNAME/../puppet.conf" ]; then
+ $SUDO rm -f /etc/puppet/puppet.conf
+ $SUDO ln -s $DIRNAME/../puppet.conf /etc/puppet/puppet.conf
+fi
diff --git a/puppet/bin/submodules b/puppet/bin/submodules
new file mode 100755
index 0000000..960d290
--- /dev/null
+++ b/puppet/bin/submodules
@@ -0,0 +1,38 @@
+#!/bin/bash
+#
+# Setup submodules.
+#
+
+# Parameters
+DIRNAME="`dirname $0`"
+
+# Usage
+function usage {
+ echo "Usage: $1 add-submodules <DIR>"
+ exit $2
+}
+
+# Set puppet folder
+if [ -d "puppet" ]; then
+ PUPPET_FOLDER="puppet"
+else
+ PUPPET_FOLDER="."
+fi
+
+# Get module list
+repos="`grep = $DIRNAME/../.mrconfig | cut -d = -f 2 | cut -d ' ' -f 4`"
+
+# Add submodules
+for repo in $repos; do
+ module="`basename $repo .git | sed -e s/^puppet-//`"
+ if [ ! -d "$PUPPET_FOLDER/modules/$module" ]; then
+ echo "Processing puppet module $module..."
+ git submodule add -f $repo $PUPPET_FOLDER/modules/$module
+ elif [ -e "modules/$module/.git" ]; then
+ # The puppet module exists and is a git submodule, so update it
+ ( cd $PUPPET_FOLDER/modules/$module && git pull origin master )
+ fi
+done
+
+# Update all modules
+git submodule update --init
diff --git a/puppet/bin/subtrees b/puppet/bin/subtrees
new file mode 100755
index 0000000..19211f1
--- /dev/null
+++ b/puppet/bin/subtrees
@@ -0,0 +1,48 @@
+#!/bin/bash
+#
+# Setup subtrees.
+#
+
+# Parameters
+DIRNAME="`dirname $0`"
+
+# Usage
+function usage {
+ echo "Usage: $1 add-submodules <DIR>"
+ exit $2
+}
+
+# Check for git-subtree
+if ! which git-subtree &> /dev/null; then
+ echo "fatal: please install git-subtree"
+ exit 1
+fi
+
+# Set puppet folder
+if [ -d "puppet" ]; then
+ PUPPET_FOLDER="puppet"
+else
+ PUPPET_FOLDER="."
+fi
+
+# Get module list
+repos="`grep = $DIRNAME/../.mrconfig | cut -d = -f 2 | cut -d ' ' -f 4`"
+
+# Add subtrees
+for repo in $repos; do
+ module="`basename $repo .git | sed -e s/^puppet-//`"
+ if [ ! -d "$PUPPET_FOLDER/modules/$module" ]; then
+ echo "Processing puppet module $module..."
+ git remote add $module $repo
+ git subtree add --prefix $PUPPET_FOLDER/modules/$module $module master --squash
+ elif [ ! -d "modules/$module/.git" ]; then
+ # The puppet module exists and is a subtree, so update it
+ if ! git remote | grep -qe "^$module$"; then
+ git remote add $module $repo
+ fi
+
+ # Update subtrees
+ git fetch $module master
+ git subtree pull --prefix $PUPPET_FOLDER/modules/$module $module master --squash
+ fi
+done
diff --git a/puppet/bin/symlinks b/puppet/bin/symlinks
new file mode 100755
index 0000000..a2f27cf
--- /dev/null
+++ b/puppet/bin/symlinks
@@ -0,0 +1,37 @@
+#!/bin/bash
+#
+# Setup symlinks.
+#
+
+# Parameters
+BASENAME="`basename $0`"
+MODULES="$1"
+
+# Check parameters
+if [ -z "$MODULES" ]; then
+ echo "Usage: $BASENAME <submodules-folder>"
+ exit 1
+elif [ ! -e "$MODULES" ]; then
+ echo "Not found: $MODULES"
+fi
+
+# Set puppet folder
+if [ -d "puppet" ]; then
+ PUPPET_FOLDER="puppet"
+else
+ PUPPET_FOLDER="."
+fi
+
+# Add module symlinks using absolute folders
+for module in `ls $MODULES`; do
+ if [ "$module" == "bootstrap" ]; then
+ continue
+ fi
+
+ if echo "$module" | grep -q "^site_"; then
+ continue
+ fi
+
+ path="`cd $MODULES/$module && pwd`"
+ ( cd $PUPPET_FOLDER/modules &> /dev/null && ln -sf $path )
+done
diff --git a/puppet/bin/syncmodules b/puppet/bin/syncmodules
new file mode 100755
index 0000000..1585aa4
--- /dev/null
+++ b/puppet/bin/syncmodules
@@ -0,0 +1,37 @@
+#!/bin/bash
+#
+# Setup symlinks.
+#
+
+# Parameters
+BASENAME="`basename $0`"
+MODULES="$1"
+
+# Check parameters
+if [ -z "$MODULES" ]; then
+ echo "Usage: $BASENAME <submodules-folder>"
+ exit 1
+elif [ ! -e "$MODULES" ]; then
+ echo "Not found: $MODULES"
+fi
+
+# Set puppet folder
+if [ -d "puppet" ]; then
+ PUPPET_FOLDER="puppet"
+else
+ PUPPET_FOLDER="."
+fi
+
+# Add module symlinks using absolute folders
+for module in `ls $MODULES`; do
+ if [ "$module" == "bootstrap" ]; then
+ continue
+ fi
+
+ if echo "$module" | grep -q "^site_"; then
+ continue
+ fi
+
+ path="`cd $MODULES/$module && pwd`"
+ ( cd $PUPPET_FOLDER/modules &> /dev/null && rsync -av --delete $path/ $module/ )
+done