2023-04-26 21:48:32 +00:00
|
|
|
#!/usr/bin/env sh
|
2023-04-20 21:34:25 +00:00
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
printf '%s\n' "Usage:"
|
|
|
|
printf '$ %s\n' "$0 [-h|--help]"
|
2023-04-26 17:34:53 +00:00
|
|
|
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]"
|
2023-04-20 21:34:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
install_modules() {
|
|
|
|
if [ -z "$(ansible-galaxy collection list community.general 2>/dev/null)" ]; then
|
|
|
|
ansible-galaxy collection install community.general
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
cd "$(dirname "$0")" || exit 255
|
2023-04-26 17:34:53 +00:00
|
|
|
if [ "$1" = "--dry" ]; then
|
|
|
|
EXEC="echo"
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
EXEC="eval"
|
|
|
|
fi
|
|
|
|
|
2023-04-20 21:34:25 +00:00
|
|
|
BASE_CMD="ansible-playbook playbook.yml --ask-vault-pass --ask-become-pass"
|
2023-04-26 17:34:53 +00:00
|
|
|
TAG="$1"
|
|
|
|
shift
|
2023-04-20 21:34:25 +00:00
|
|
|
|
2023-04-26 17:34:53 +00:00
|
|
|
case $TAG in
|
2023-04-20 21:34:25 +00:00
|
|
|
"")
|
|
|
|
install_modules; $BASE_CMD ;;
|
|
|
|
os|docker)
|
2023-04-26 17:34:53 +00:00
|
|
|
install_modules; $BASE_CMD --tags "$TAG" ;;
|
2023-04-20 21:34:25 +00:00
|
|
|
users)
|
|
|
|
install_modules
|
2023-04-26 17:34:53 +00:00
|
|
|
|
|
|
|
if [ "$1" = "-i" ] || [ "$1" = "--init" ]; then
|
|
|
|
$EXEC "$BASE_CMD --user root --tags '$TAG'"
|
2023-04-20 21:34:25 +00:00
|
|
|
else
|
2023-04-26 17:34:53 +00:00
|
|
|
$EXEC "$BASE_CMD --tags '$TAG'"
|
2023-04-20 21:34:25 +00:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
reboot)
|
|
|
|
install_modules
|
2023-04-26 17:34:53 +00:00
|
|
|
|
|
|
|
if [ "$1" = "-f" ] || [ "$1" = "--force" ]; then
|
|
|
|
$EXEC "$BASE_CMD --tags '$TAG' --extra-vars 'force_reboot=true'"
|
2023-04-20 21:34:25 +00:00
|
|
|
else
|
2023-04-26 17:34:53 +00:00
|
|
|
$EXEC "$BASE_CMD --tags '$TAG' --extra-vars 'reboot=true'"
|
2023-04-20 21:34:25 +00:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
services)
|
|
|
|
install_modules
|
2023-04-26 17:34:53 +00:00
|
|
|
|
|
|
|
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'"}'
|
2023-04-20 21:34:25 +00:00
|
|
|
fi
|
2023-04-26 17:34:53 +00:00
|
|
|
|
|
|
|
$EXEC "$BASE_CMD --tags '$TAG' $(test -z "$VARS" || echo "--extra-vars '$VARS'")"
|
2023-04-20 21:34:25 +00:00
|
|
|
;;
|
|
|
|
-h|--help)
|
|
|
|
usage ;;
|
|
|
|
*)
|
|
|
|
usage >&2; exit 1 ;;
|
|
|
|
esac
|