Skip to content

Instantly share code, notes, and snippets.

@heyseus1
Last active August 29, 2015 14:19
Show Gist options
  • Save heyseus1/9d65904d5287b72df68a to your computer and use it in GitHub Desktop.
Save heyseus1/9d65904d5287b72df68a to your computer and use it in GitHub Desktop.
Puppet Install for ubuntu OR centOS 6.x
#!/usr/bin/env bash
#
# This bootstraps Puppet on Ubuntu or CentOS 6.x.
#
set -e
checkroot() {
if [ $UID -ne 0 ] ; then
echo "User has insufficient privilege."
exit 4
fi
}
display_os() {
/bin/date
/bin/uname -r
. /etc/lsb-release
dmidecode -t 1 | grep -i 'serial' | sed 's/^ *//'
cat /etc/*-release
dmidecode -t system -q | egrep -i 'Manufacturer: |Product|UUID' | \
sed 's/^ *//'
dmidecode -t bios -q | egrep -i 'version|vendor' | \
sed 's/^ *//'
}
Ubuntu_Build() {
if [ -n "$(cat /etc/*-release | grep 'DISTRIB_ID=Ubuntu')" ]; then
REPO_DEB_URL; puppet_check; Puppet_install; Ruby_Gems
else
echo "skipping Ubuntu build"
fi
}
REPO_DEB_URL() {
REPO_DEB_URL="http://apt.puppetlabs.com/puppetlabs-release-${DISTRIB_CODENAME}.deb"
}
puppet_check() {
if which puppet > /dev/null 2>&1 -a apt-cache policy | grep --quiet apt.puppetlabs.com; then
echo "Puppet already exists. Exiting"
exit 0
fi
}
Puppet_install() {
echo "updating"
apt-get update >/dev/null
echo "Installing wget"
apt-get install -y wget >/dev/null
echo "Configuring PuppetLabs repository"
repo_deb_path=$(mktemp)
wget --output-document="${repo_deb_path}" "${REPO_DEB_URL}" 2>/dev/null
dpkg -i "${repo_deb_path}" >/dev/null
apt-get update >/dev/null
echo "Installing Puppet"
DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install puppet >/dev/null
echo "Installation successful"
}
Ruby_Gems() {
if [ $DISTRIB_CODENAME != "trusty" ]; then
apt-get install -y rubygems >/dev/null
fi
gem install --no-ri --no-rdoc rubygems-update
update_rubygems >/dev/null
}
CentOS6.5_Build() {
if [ -n "$(cat /etc/*-release | grep 'CentOS release 6.')" ]; then
REPO_URL; puppet_centOS_check; display_os; puppet_centOS_install
else
echo "skipping CentOS build"
fi
}
REPO_URL() {
REPO_URL="http://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm"
}
puppet_centOS_check() {
if which puppet > /dev/null 2>&1; then
echo "Puppet is already installed."
exit 0
fi
}
puppet_centOS_install (){
echo "Configuring PuppetLabs repo..."
repo_path=$(mktemp)
wget --output-document="${repo_path}" "${REPO_URL}" 2>/dev/null
rpm -i "${repo_path}" >/dev/null
echo "Installing puppet"
yum install -y puppet > /dev/null
echo "Puppet installed!"
}
checkroot
display_os
Ubuntu_Build
CentOS6.5_Build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment