Add option do bring services down and to dry-run provision.sh
This commit is contained in:
parent
6467999ae4
commit
72288bdbcf
57
provision.sh
57
provision.sh
|
@ -5,11 +5,11 @@ set -e
|
|||
usage() {
|
||||
printf '%s\n' "Usage:"
|
||||
printf '$ %s\n' "$0 [-h|--help]"
|
||||
printf '$ %s\n' "$0 os"
|
||||
printf '$ %s\n' "$0 docker"
|
||||
printf '$ %s\n' "$0 users [-i|--init]"
|
||||
printf '$ %s\n' "$0 reboot [-f|--force]"
|
||||
printf '$ %s\n' "$0 services [SINGLE_SERVICE]"
|
||||
printf '$ %s\n' "$0 [--dry] os"
|
||||
printf '$ %s\n' "$0 [--dry] docker"
|
||||
printf '$ %s\n' "$0 [--dry] users [-i|--init]"
|
||||
printf '$ %s\n' "$0 [--dry] reboot [-f|--force]"
|
||||
printf '$ %s\n' "$0 [--dry] services [-d|--down] [SINGLE_SERVICE]"
|
||||
}
|
||||
|
||||
install_modules() {
|
||||
|
@ -19,36 +19,57 @@ install_modules() {
|
|||
}
|
||||
|
||||
cd "$(dirname "$0")" || exit 255
|
||||
BASE_CMD="ansible-playbook playbook.yml --ask-vault-pass --ask-become-pass"
|
||||
if [ "$1" = "--dry" ]; then
|
||||
EXEC="echo"
|
||||
shift
|
||||
else
|
||||
EXEC="eval"
|
||||
fi
|
||||
|
||||
case $1 in
|
||||
BASE_CMD="ansible-playbook playbook.yml --ask-vault-pass --ask-become-pass"
|
||||
TAG="$1"
|
||||
shift
|
||||
|
||||
case $TAG in
|
||||
"")
|
||||
install_modules; $BASE_CMD ;;
|
||||
os|docker)
|
||||
install_modules; $BASE_CMD --tags "$1" ;;
|
||||
install_modules; $BASE_CMD --tags "$TAG" ;;
|
||||
users)
|
||||
install_modules
|
||||
if [ "$2" = "-i" ] || [ "$2" = "--init" ]; then
|
||||
$BASE_CMD --user root --tags "$1"
|
||||
|
||||
if [ "$1" = "-i" ] || [ "$1" = "--init" ]; then
|
||||
$EXEC "$BASE_CMD --user root --tags '$TAG'"
|
||||
else
|
||||
$BASE_CMD --tags "$1"
|
||||
$EXEC "$BASE_CMD --tags '$TAG'"
|
||||
fi
|
||||
;;
|
||||
reboot)
|
||||
install_modules
|
||||
if [ "$2" = "-f" ] || [ "$2" = "--force" ]; then
|
||||
$BASE_CMD --tags "$1" --extra-vars "force_reboot=true"
|
||||
|
||||
if [ "$1" = "-f" ] || [ "$1" = "--force" ]; then
|
||||
$EXEC "$BASE_CMD --tags '$TAG' --extra-vars 'force_reboot=true'"
|
||||
else
|
||||
$BASE_CMD --tags "$1" --extra-vars "reboot=true"
|
||||
$EXEC "$BASE_CMD --tags '$TAG' --extra-vars 'reboot=true'"
|
||||
fi
|
||||
;;
|
||||
services)
|
||||
install_modules
|
||||
if [ -z "$2" ]; then
|
||||
$BASE_CMD --tags "$1"
|
||||
else
|
||||
$BASE_CMD --tags "$1" --extra-vars "single_service=$2"
|
||||
|
||||
if [ "$1" = "-d" ] || [ "$1" = "--down" ]; then
|
||||
DOWN=1
|
||||
shift
|
||||
fi
|
||||
|
||||
if [ -z "$DOWN" ] && [ -n "$1" ]; then
|
||||
VARS="single_service=$1"
|
||||
elif [ -n "$DOWN" ] && [ -z "$1" ]; then
|
||||
VARS="stop=true"
|
||||
elif [ -n "$DOWN" ] && [ -n "$1" ]; then
|
||||
VARS='{"stop": true, "single_service": "'$1'"}'
|
||||
fi
|
||||
|
||||
$EXEC "$BASE_CMD --tags '$TAG' $(test -z "$VARS" || echo "--extra-vars '$VARS'")"
|
||||
;;
|
||||
-h|--help)
|
||||
usage ;;
|
||||
|
|
Reference in a new issue