82 lines
2 KiB
Bash
Executable file
82 lines
2 KiB
Bash
Executable file
#!/usr/bin/env sh
|
|
|
|
set -e
|
|
|
|
usage() {
|
|
printf '%s\n' "Usage:"
|
|
printf '$ %s\n' "$0 [-h|--help]"
|
|
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() {
|
|
if [ -z "$(ansible-galaxy collection list community.general 2>/dev/null)" ]; then
|
|
ansible-galaxy collection install community.general
|
|
fi
|
|
}
|
|
|
|
BASE_CMD="ansible-playbook playbook.yml --ask-vault-pass --ask-become-pass"
|
|
cd "$(dirname "$0")" || exit 255
|
|
|
|
if [ "$1" = "--dry" ]; then
|
|
EXEC="echo"
|
|
shift
|
|
else
|
|
EXEC="eval"
|
|
fi
|
|
|
|
if [ "$#" -gt 0 ]; then
|
|
TAG="$1"
|
|
shift
|
|
fi
|
|
|
|
case $TAG in
|
|
"")
|
|
install_modules; $EXEC "$BASE_CMD" ;;
|
|
os|docker|firewall|ssh)
|
|
install_modules; $EXEC "$BASE_CMD --tags '$TAG'" ;;
|
|
users)
|
|
install_modules
|
|
|
|
if [ "$1" = "-i" ] || [ "$1" = "--init" ]; then
|
|
$EXEC "$BASE_CMD --user root --tags '$TAG'"
|
|
else
|
|
$EXEC "$BASE_CMD --tags '$TAG'"
|
|
fi
|
|
;;
|
|
reboot)
|
|
install_modules
|
|
|
|
if [ "$1" = "-f" ] || [ "$1" = "--force" ]; then
|
|
$EXEC "$BASE_CMD --tags '$TAG' --extra-vars 'force_reboot=true'"
|
|
else
|
|
$EXEC "$BASE_CMD --tags '$TAG' --extra-vars 'reboot=true'"
|
|
fi
|
|
;;
|
|
services)
|
|
install_modules
|
|
|
|
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 ;;
|
|
*)
|
|
usage >&2; exit 1 ;;
|
|
esac
|