Puppet agent Install Using Script

by

Please shareShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on RedditDigg thisShare on StumbleUpon

With this script, you can install puppet agents in few minutes on Red Hat or Debian based systems.

Make a puppet script file,

# vi puppetscript.sh

Add the following contents:

 ##############################################################################
 #!/usr/bin/env bash
 set -e
 set -u
 EXPECTED_ARGS=2
 E_BADARGS=65
 if [ $# -ne $EXPECTED_ARGS ]
 then
 echo "Usage: $0 master_hostname node_hostname"
 exit $E_BADARGS
 fi# Detect OS [https://github.com/coto/server-easy-install/blob/master/lib/core.sh]lowercase(){
 echo "$1" | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/"
 }OS=`lowercase \`uname\``
 KERNEL=`uname -r`
 MACH=`uname -m`

if [ "{$OS}" == "windowsnt" ]; then
 OS=windows
 elif [ "{$OS}" == "darwin" ]; then
 OS=mac
 else
 OS=`uname`
 if [ "${OS}" = "SunOS" ] ; then
 OS=Solaris
 ARCH=`uname -p`
 OSSTR="${OS} ${REV}(${ARCH} `uname -v`)"
 elif [ "${OS}" = "AIX" ] ; then
 OSSTR="${OS} `oslevel` (`oslevel -r`)"
 elif [ "${OS}" = "Linux" ] ; then
 if [ -f /etc/redhat-release ] ; then
 DistroBasedOn='RedHat'
 DIST=`cat /etc/redhat-release |sed s/\ release.*//`
 PSUEDONAME=`cat /etc/redhat-release | sed s/.*\(// | sed s/\)//`
 REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//`
 elif [ -f /etc/SuSE-release ] ; then
 DistroBasedOn='SuSe'
 PSUEDONAME=`cat /etc/SuSE-release | tr "\n" ' '| sed s/VERSION.*//`
 REV=`cat /etc/SuSE-release | tr "\n" ' ' | sed s/.*=\ //`
 elif [ -f /etc/mandrake-release ] ; then
 DistroBasedOn='Mandrake'
 PSUEDONAME=`cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//`
 REV=`cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//`
 elif [ -f /etc/debian_version ] ; then
 DistroBasedOn='Debian'
 DIST=`cat /etc/lsb-release | grep '^DISTRIB_ID' | awk -F= '{ print $2 }'`
 PSUEDONAME=`cat /etc/lsb-release | grep '^DISTRIB_CODENAME' | awk -F= '{ print $2 }'`
 REV=`cat /etc/lsb-release | grep '^DISTRIB_RELEASE' | awk -F= '{ print $2 }'`
 fi
 if [ -f /etc/UnitedLinux-release ] ; then
 DIST="${DIST}[`cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//`]"
 fi
 OS=`lowercase $OS`
 DistroBasedOn=`lowercase $DistroBasedOn`
 readonly OS
 readonly DIST
 readonly DistroBasedOn
 readonly PSUEDONAME
 readonly REV
 readonly KERNEL
 readonly MACH
 fi
fi

MASTER_HOSTNAME=$1
 NODE_HOSTNAME=$2

hostname $NODE_HOSTNAME

case $DistroBasedOn in
 debian)
 echo $NODE_HOSTNAME > /etc/hostname
 apt-get -y install wget
 wget http://apt.puppetlabs.com/puppetlabs-release-precise.deb
 dpkg -i puppetlabs-release-precise.deb
 apt-get update
 apt-get -y install puppet
 ;;
 redhat)
 echo "NETWORKING=yes" > /etc/sysconfig/network
 echo "HOSTNAME=$NODE_HOSTNAME" >> /etc/sysconfig/network
 rpm -ivh http://yum.puppetlabs.com/el/6/products/i386/puppetlabs-release-6-6.noarch.rpm || true
 yum -y install puppet
 ;;
 *)
 echo "Your operating system does not compatible with the script"
 exit 1
 esac

echo "[main]
 logdir=/var/log/puppet
 vardir=/var/lib/puppet
 ssldir=/var/lib/puppet/ssl
 rundir=/var/run/puppet
 factpath=\$vardir/lib/facter
 templatedir=\$confdir/templates
 server=$MASTER_HOSTNAME
 report=true
 pluginsync=true
 [master]
 # These are needed when the puppetmaster is run by passenger
 # and can safely be removed if webrick is used.
 ssl_client_header = SSL_CLIENT_S_DN
 ssl_client_verify_header = SSL_CLIENT_VERIFY" > /etc/puppet/puppet.conf

case $DistroBasedOn in
 debian)
 echo '# Defaults for puppet - sourced by /etc/init.d/puppet

# Start puppet on boot?
 START=yes

# Startup options
 DAEMON_OPTS=""' > /etc/default/puppet
 ;;
 esac

puppet resource service puppet ensure=running enable=true

################################################################################

Please run the script as shown in the below command:

# chmod +x puppetscript
# ./puppetscript  master-hostnane agent-hostname

Script from ideaonsails.