Skip to content

Instantly share code, notes, and snippets.

@CYPI
Created October 4, 2018 18:23
Show Gist options
  • Save CYPI/db03d09e4ef0538724ca4bc1c765c3db to your computer and use it in GitHub Desktop.
Save CYPI/db03d09e4ef0538724ca4bc1c765c3db to your computer and use it in GitHub Desktop.
testing puppet branch on a remote node
#! /bin/bash
if [[ "$1" == "-h" || "$1" == "--help" ]];
then
echo "Usage: whatwouldhappenon.sh [host_name]"
echo "the script runs your puppet branch environment in noop mode on a [ host_name ] to test your changes"
echo "it grabs your branch name automatically or ask for it if it doesn't find it"
exit 0
fi
# target [host_name] where you will run puppet agent on in noop mode
SERVER=$1
PUPPETSERVER="<puppet_server>"
# getting the current git branch and if it doesnt find it, ask for it
BRANCH=$(git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/\1/p')
if [ -z $BRANCH ]
then
read -p "what's your git branch name?" BRANCH
fi
# puppet environment folder in puppet master
PUPPETENV="/opt/puppet_envs/$BRANCH"
# checking if your environment based on your git branch name exist in puppet master
ro=$(echo "if [ ! -d "$PUPPETENV" ]; then echo "nope"; fi" | ssh -T -A $PUPPETSERVER)
if [[ $ro =~ nope$ ]]; then
echo "your puppet environment is not ready yet"
exit 1
fi
# executing puppent agent within your environment in noop mode on [host_name]
echo "###########################################################################################"
echo "WARNING: RESOURCES WILL STILL BE EXPORTED even if you're running the puppetenv in noop mode"
echo "###########################################################################################"
echo ""
ssh -tt -A $SERVER<<EOT
sudo -i
puppetenv -b $BRANCH -n && exit
EOT
exit
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment