Skip to content

Instantly share code, notes, and snippets.

@dol
Last active December 18, 2015 11:29
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dol/5776169 to your computer and use it in GitHub Desktop.
Save dol/5776169 to your computer and use it in GitHub Desktop.
Preinstall puppet via puppetlabs repo

Custom puppet version preinstall for vagrant

Add the following line to you 'Vagrantfile':

config.vm.provision :shell do |s|
  s.path = "preinstall.sh"
  s.args = "3.1.1-1puppetlabs1"
end
#!/usr/bin/env bash
# Pre install script to install the a specific version of puppet
# If no parameter is supplied, the lastest version will be installed
VERSION=""
if [ -n "$1" ]
then
VERSION="$1"
fi
echo "#### START preinstall ####"
PUPPETLABS_RELEASE_INSTALLED=$(dpkg -s puppetlabs-release 2>/dev/null|grep installed)
if [ "$PUPPETLABS_RELEASE_INSTALLED" == "" ]; then
echo "Installing puppetlabs-release"
rm -rf /tmp/puppetlabs-release-precise.deb 1>/dev/null 2>&1
wget -P /tmp http://apt.puppetlabs.com/puppetlabs-release-precise.deb 1>/dev/null 2>&1
sudo dpkg -i /tmp/puppetlabs-release-precise.deb 1>/dev/null 2>&1
sudo apt-get update 1>/dev/null 2>&1
rm -rf /tmp/puppetlabs-release-precise.deb 1>/dev/null 2>&1
fi
echo "Puppetlabs-release installed."
# Check if the defined version exists
VERSION_START=0
VERSION_FOUND=0
ALL_VERSIONS=""
stripped_info=$(apt-cache showpkg puppet | grep -v '^\( \|$\)' | awk -F, '{ print $1; }')
while read line; do
if [ "$VERSION_START" -eq 1 ]; then
case "$line" in
*:)
VERSION_START=0
break
;;
esac
if [ "Versions:" == "$line" ]; then
VERSION_START=1
fi
line_split=( $line )
ALL_VERSIONS="$ALL_VERSIONS${line_split[0]}\n"
if [ "${line_split[0]}" == "$VERSION" ]; then
VERSION_FOUND=1
fi
fi
if [ "Versions:" == "$line" ]; then
VERSION_START=1
fi
done <<< "$stripped_info"
# If no version was declared install the latest
if [ -z "$VERSION" ]
then
VERSION=$(echo -e "$ALL_VERSIONS" | head -n 1)
VERSION_FOUND=1
fi
if [ "$VERSION_FOUND" -eq 0 ]; then
echo
echo "Error: Supplied version ($VERSION) is not available. Please use one of the following versions:"
echo -e "$ALL_VERSIONS"
else
PUPPET_INSTALLED=$(dpkg -s puppet 2>/dev/null|grep -e "installed" -e "Version: $VERSION"|wc -l|grep 2)
if [ "$PUPPET_INSTALLED" == "" ]; then
echo "Installing puppet version $VERSION"
apt-get -y --force-yes install puppet-common=$VERSION 1>/dev/null 2>&1
apt-get -y --force-yes install puppet=$VERSION 1>/dev/null 2>&1
fi
PUPPET_VERSION_CHECK=$(puppet --version)
split_version=(${VERSION//-/ })
if [ "$PUPPET_VERSION_CHECK" != "${split_version[0]}" ]; then
echo "Error: Installed version of puppet not matching the install requirement."
else
echo "Puppet (${split_version[0]}) successfully installed."
fi
fi
echo "#### END preinstall ####"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment