Created
March 14, 2016 13:35
-
-
Save giuliocalzolari/c3749c9abdfe5eb66cdf to your computer and use it in GitHub Desktop.
puppet-sync
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PIDFILE="/var/run/puppet-sync.pid" | |
TMPFLD="/usr/src/puppet_local_repo" | |
DEPLOYTMPFLD="/etc/puppet" | |
removePID () { | |
rm -rf $PIDFILE | |
} | |
die () { | |
DATE='date +%Y/%m/%d:%H:%M:%S' | |
echo "[${DATE}] $1" | |
echo >&2 "$@" | |
removePID | |
exit 1 | |
} | |
VERBOSE="disable" | |
FORCE='false' | |
while getopts "vf" opt; do | |
case $opt in | |
f) | |
#echo "Target Host: $OPTARG" >&2 | |
FORCE="true" | |
;; | |
v) | |
VERBOSE="enable" | |
;; | |
esac | |
done | |
function echo_log { | |
DATE='date +%Y/%m/%d:%H:%M:%S' | |
echo "[${DATE}] $1" | |
} | |
# Pid control and creation | |
if [ -f "$PIDFILE" ];then | |
if [ ! -d /proc/$(cat $PIDFILE) ]; then | |
echo_log "Invalid PID sync" | |
rm -rf $PIDFILE | |
echo $$ > $PIDFILE | |
if [[ $? -ne 0 ]] ; then | |
die "Error on PID creation" | |
fi | |
else | |
echo_log "Found another sync" | |
exit 0 | |
fi | |
else | |
echo $$ > $PIDFILE | |
if [[ $? -ne 0 ]] ; then | |
die "Error on PID creation" | |
fi | |
fi | |
# check puppet main folder | |
if [ ! -d "$DEPLOYTMPFLD" ];then | |
die "puppet folder NOT Found" | |
fi | |
if [ -d "$TMPFLD" ];then | |
# local repo exist execute pull | |
echo_log "Pull PuppetCode" | |
cd $TMPFLD; | |
git pull | |
else | |
# local repo miss execute clone | |
echo_log "Clone PuppetCode" | |
git clone [[[[[GIT REPO ]]]]] $TMPFLD --quiet | |
if [[ $? -ne 0 ]] ; then | |
die "Error on git clone" | |
fi | |
fi | |
cd $TMPFLD | |
echo_log "validate Code" | |
puppet parser validate manifests/*.pp | |
if [[ $? -ne 0 ]] ; then | |
die "Error validate manifests" | |
fi | |
puppet parser validate modules/*/manifests/*.pp | |
if [[ $? -ne 0 ]] ; then | |
die "Error validate module" | |
fi | |
echo_log "Deploy PuppetCode" | |
rsync -azvil --delete-before --rsync-path='sudo rsync' --exclude=auth.conf --exclude=routes.yaml --exclude=puppetdb.conf --exclude=autosign.conf --exclude puppet.conf --exclude=node.rb --exclude=.hg/ --exclude=.git/ --exclude=sensitive.csv $TMPFLD/ $DEPLOYTMPFLD/ | |
if [[ $? -ne 0 && $? -ne 24 ]] ;then | |
die "Error on rsync" | |
fi | |
removePID | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment