Skip to content

Instantly share code, notes, and snippets.

@jordigg
Last active February 21, 2017 15:01
Show Gist options
  • Save jordigg/e0c3a589b9a669aa5012 to your computer and use it in GitHub Desktop.
Save jordigg/e0c3a589b9a669aa5012 to your computer and use it in GitHub Desktop.
Puppet agent bootstrap for Debian based systems (Debian, Ubuntu)
#!/usr/bin/env bash
#
# This bootstraps Puppet on Debian based systems
#
# To install latest version run as --> PUPPET_COLLECTION=pc1 ROLE=role TYPE=type ./ubuntu_bootstrap.sh
# role and type variables are custom_facts with the same name
# role can be: engineering, teamcityagent, puppetserver, puppetdb... or empty.
# type can be server or workstation. Defaults to workstation if not defined.
set -e
# Load up Codename Release
DISTRIB_CODENAME=$(lsb_release -sc)
# if PUPPET_COLLECTION is not prepended with a dash "-", add it
[[ "${PUPPET_COLLECTION}" == "" ]] || [[ "${PUPPET_COLLECTION:0:1}" == "-" ]] || \
PUPPET_COLLECTION="-${PUPPET_COLLECTION}"
DEB_FILE_NAME="puppetlabs-release${PUPPET_COLLECTION}-${DISTRIB_CODENAME}.deb"
REPO_DEB_URL="http://apt.puppetlabs.com/${DEB_FILE_NAME}"
#--------------------------------------------------------------------
# NO TUNABLES BELOW THIS POINT
#--------------------------------------------------------------------
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root." >&2
exit 1
fi
if which puppet > /dev/null 2>&1 && apt-cache policy | grep --quiet apt.puppetlabs.com; then
echo "Puppet is already installed."
exit 0
fi
# Install the PuppetLabs repo
echo "Configuring PuppetLabs repo..."
apt-get update && apt-get -y install curl
wget -P /tmp ${REPO_DEB_URL} 2>/dev/null
dpkg -i /tmp/${DEB_FILE_NAME} >/dev/null
curl -o /tmp/DEB-GPG-KEY-puppet --remote-name --location https://apt.puppetlabs.com/DEB-GPG-KEY-puppet && \
gpg --keyid-format 0xLONG --with-fingerprint /tmp/DEB-GPG-KEY-puppet && \
apt-key add /tmp/DEB-GPG-KEY-puppet >/dev/null
apt-get update >/dev/null
# Install Puppet
echo "Installing Puppet..."
apt-get install -y puppet-agent >/dev/null
echo "Adding Puppet to PATH..."
echo 'PATH="'$PATH':/opt/puppetlabs/bin"' > /etc/environment
export PATH=$PATH:/opt/puppetlabs/bin
# Create custom facts folder
mkdir -p /etc/facter/facts.d
# Add custom facts
if [ "${ROLE}" != "" ]; then
echo "Adding Role ${ROLE}"
echo "role=${ROLE}" > /etc/facter/facts.d/role.txt
fi
if [ "${TYPE}" != "" ]; then
echo "Adding Node type ${TYPE}"
echo "type=${TYPE}" > /etc/facter/facts.d/type.txt
else
echo "Adding Node type desktop"
echo "type=desktop" > /etc/facter/facts.d/type.txt
fi
echo "Puppet installed! Running for first time..."
puppet agent -t
echo "Starting puppet service"
puppet resource service puppet ensure=running enable=true
echo "Success, puppet setup and running. Please reload your shell to use the puppet command"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment