Skip to content

Instantly share code, notes, and snippets.

@lorello
Created March 8, 2016 13:36
Show Gist options
  • Select an option

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

Select an option

Save lorello/9fe7fe5fd5388edcf133 to your computer and use it in GitHub Desktop.
Puppet utils
set -e
[ ! -d .git ] && echo "Not a git repo, fatal error" && exit 1
[ ! -d log ] && mkdir log && echo "Create log dir"
if [ ! -f log/.keep ]; then
touch log/.keep
echo "Create log/.keep file"
git add log/.keep
git commit -m "Added log dir for git-deploy log file" log/.keep
if [ ! -f .gitignore ]; then
echo 'Create .gitignore file'
echo 'log/' >> .gitignore
git add .gitignore
git commit -m "created .gitignore file"
fi
fi
#!/bin/bash
set -e
[ ! -d .git ] && echo "Not a git repo, fatal error" && exit 1
~/bin/git-deploy-add-log-dir
MODNAME=$(basename $PWD)
REMOTE_NAME=${2:-antibrote}
REMOTE_DIR=${1:-/usr/share/puppet/modules/$MODNAME}
REMOTE="lorenzo.salvadorini@antibrote-puppetmaster01.aws.softecspa.it:$REMOTE_DIR"
echo -e "Press any key to add remote:\n\t$REMOTE\nor add a parameter to specify the remote directory"
read X
git remote add $REMOTE_NAME $REMOTE
echo "Setting up remote to receive deploy..."
git deploy setup -r antibrote --shared
echo "Making first pull from remote..."
git pull antibrote master
#!/bin/bash
# push to origin and to prod
MESSAGE=$1
REMOTE=${2:-antibrote}
BRANCH=${3:-master}
if [ -z "$MESSAGE" ]; then
echo -e "\nMissing commit message\n\nSyntax:\n\t$0 <commit-message> [remote] [branch]\n\n"
echo -e "Pushes always to origin and to [remote]/[branch], where remote by default is 'antibrote/master'"
exit 1
fi
echo -e "\n# Testing changes..."
puppet-tests || exit 1
git commit -m "$MESSAGE" -a
echo -e "\n# Pushing to GitLab..."
git push origin master || exit 1
echo -e "\n# Pushing to $REMOTE $BRANCH ..."
git push $REMOTE $BRANCH
#!/bin/bash
# Simple syntax check of Puppet Source Code, ERB Templates,
# pass anything to force checking of all files
FORCE=${1:-0}
GIT_DIFF_CMD="git diff --name-only --diff-filter=ACMR $OLD_REVISION $REVISION"
declare -i RESULT=0
set +e # Don't exit on error. Collect the errors instead.
if [ "$FORCE" -eq 1 ]; then
YAML_PATH_LIST=`find -name '*.yaml' | grep -v "modules"`
else
YAML_PATH_LIST=`$GIT_DIFF_CMD | grep -F '.yaml'`
fi
echo 'YAML files to check syntax:'; echo "$YAML_PATH_LIST"; echo "";
for YAML_PATH in $YAML_PATH_LIST; do
ruby -e "require 'yaml'; YAML.load_file('${YAML_PATH}')"
RESULT+=$?
done
if [ "$FORCE" -eq 1 ]; then
ERB_PATH_LIST=`find -name '*.erb' | grep -v modules`
else
ERB_PATH_LIST=`$GIT_DIFF_CMD | grep -F '.erb'`
fi
echo 'ERB files to check syntax:'; echo "$ERB_PATH_LIST"; echo "";
for ERB_PATH in $ERB_PATH_LIST; do
erb -x -T '-' -P $ERB_PATH | ruby -c
RESULT+=$?
done
if [ "$FORCE" -eq 1 ]; then
PP_PATH_LIST=`find -name '*.pp' | grep -v modules`
else
PP_PATH_LIST=`$GIT_DIFF_CMD | grep -F '.pp'`
fi
echo 'PP files to check syntax:'; echo "$PP_PATH_LIST"; echo "";
for PP_PATH in $PP_PATH_LIST; do
puppet parser validate $PP_PATH
RESULT+=$?
puppet-lint --fix --with-filename --fail-on-warnings --no-80chars-check $PP_PATH
done
if [ "$RESULT" -gt 0 ]; then
echo -e "\n\n$RESULT errors occurred\n"
else
echo -e "\n\nAll test successfully passed!\n"
fi
exit $RESULT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment