Skip to content

Instantly share code, notes, and snippets.

@lorello
Last active August 29, 2015 14:21
Show Gist options
  • Select an option

  • Save lorello/a3a1208e54cbdb058c7f to your computer and use it in GitHub Desktop.

Select an option

Save lorello/a3a1208e54cbdb058c7f to your computer and use it in GitHub Desktop.
Puppet masterless setup (not inside a vagrant host)
#!/bin/bash
# Setup ricette vagrant su una macchina non vagrant
#
# mi aspetto di fare il clone di repository stile vagrant
#
# /Puppetfile
# /setup/manifests/default.pp
# /setup/modules
# /setup/hiera/*.yaml
#
if [ -z $1 ]; then
echo -e "\n\n\tSyntax: $0 <repository.git> [deploy_path]\n\ndepoly_path=/opt if not specified"
exit 1
fi
# Check parameter values
REPO=$1
DESTPATH=${2:-/opt}
# Run apt-get update during first run
if [ ! -f /tmp/aptupdated.lock ]; then
echo "Updating apt repositories..."
apt-get update -qqy
touch /tmp/aptupdated.lock
fi
# on precise use package python-software-properties
apt-get install -qy git-core puppet-common software-properties-common pkg-config build-essential make augeas-tools libaugeas-ruby ruby-dev
apt-add-repository -y ppa:brightbox/ruby-ng
apt-get update -qy
apt-get install -qy ruby ruby-switch
gem install r10k --no-ri --no-rdoc
# Clone the repository
cd $DESTPATH
[ ! -d setup ] && git clone $REPO $DESTPATH
# Setup hiera, if needed
if [ -f $DESTPATH/setup/hiera.yaml ]; then
if [ ! `readlink /etc/puppet/hiera.yaml` ]; then
[ -f /etc/puppet/hiera.yaml ] && rm -f /etc/puppet/hiera.yaml
ln -s $DESTPATH/setup/hiera.yaml /etc/puppet/hiera.yaml
fi
if [ ! `readlink /etc/hiera.yaml` ]; then
[ -f /etc/hiera.yaml ] && rm -f /etc/hiera.yaml
ln -s $DESTPATH/setup/hiera.yaml /etc/hiera.yaml
fi
fi
# Puppet modules
if [ ! `readlink /etc/puppet/manifests` ]; then
[ -d /etc/puppet/manifests ] && rm -rf /etc/puppet/manifests
ln -s $DESTPATH/setup/manifests/ /etc/puppet/manifests
fi
if [ ! `readlink /etc/puppet/modules` ]; then
[ -d /etc/puppet/modules ] && rm -rf /etc/puppet/modules
ln -s $DESTPATH/setup/modules/ /etc/puppet/modules
fi
if [ ! `readlink /var/lib/hiera` ]; then
[ -d /var/lib/hiera ] && rm -rf /var/lib/hiera
ln -s $DESTPATH/setup/hiera/ /var/lib/hiera
fi
# Get puppet modules needed for our manifests
if [ -f $DESTPATH/setup/Puppetfile ]; then
cd $DESTPATH/setup
r10k puppetfile install
fi
# Add facter facts that classify this host
if [ -d /var/lib/puppet/facts.d ]; then
cp -auv $DESTPATH/setup/facts/classifiers.yaml /var/lib/puppet/facts.d
else
if [ -d /etc/facter/facts.d ]; then
cp -auv $DESTPATH/setup/facts/classifiers.yaml /etc/facter/facts.d
else
mkdir -p /etc/facter/facts.d
cp -auv $DESTPATH/setup/facts/classifiers.yaml /etc/facter/facts.d
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment