Skip to content

Instantly share code, notes, and snippets.

@olorton
Created May 19, 2014 13:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olorton/953fcc4b574e3e2f98fb to your computer and use it in GitHub Desktop.
Save olorton/953fcc4b574e3e2f98fb to your computer and use it in GitHub Desktop.
Anisble provision script
#!/bin/bash
while getopts "v:" OPTION; do
case $OPTION in
v) shift; verbose=true;;
# Unknown option. No need for an error, getopts informs
# the user itself.
\?) exit 1;;
esac
done
if [ "$#" -lt 1 ]; then
echo "Please supply production/staging/dev as an argument."
exit 1
fi
if [[ "$1" != "production" ]] && [[ "$1" != "staging" ]] && [[ "$1" != "dev" ]]; then
echo "Please use a valid argument (production, staging or dev)."
exit 1
fi
if [[ "$1" == "production" ]]; then
read -n1 -p "Do you really want to provision PRODUCTION? (y/n) "
echo
[[ ! $REPLY = [yY] ]] && echo "Exited provision script." && exit 1;
fi
if [ $verbose ]; then
cmd="ansible-playbook --inventory-file=config/ansible/hosts-"$1" -e env="$1" config/ansible/playbook.yml -v"
echo "Running ansible: (verbose)"
else
echo "Running ansible:"
cmd="ansible-playbook --inventory-file=config/ansible/hosts-"$1" -e env="$1" config/ansible/playbook.yml"
fi
echo " ${cmd}"
${cmd}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment