Created
May 19, 2014 13:39
-
-
Save olorton/953fcc4b574e3e2f98fb to your computer and use it in GitHub Desktop.
Anisble provision script
This file contains 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
#!/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