日常更新
This commit is contained in:
56
ansible/bin/deploy-lab.sh
Executable file
56
ansible/bin/deploy-lab.sh
Executable file
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
# shellcheck disable=SC1091
|
||||
source "${ROOT}/ansible/lib/lib-ansible-lab.sh"
|
||||
ansible_lab_export_config
|
||||
|
||||
load_env() {
|
||||
if [[ -f "${ROOT}/ansible/env/.env.verify" ]]; then
|
||||
set -a
|
||||
# shellcheck disable=SC1091
|
||||
source "${ROOT}/ansible/env/.env.verify"
|
||||
set +a
|
||||
echo "[OK] 已加载 ansible/env/.env.verify"
|
||||
fi
|
||||
}
|
||||
|
||||
usage() {
|
||||
cat <<'EOF'
|
||||
用法:ansible/bin/deploy-lab.sh <子命令>
|
||||
子命令:k3s | longhorn | nginx-matrix | nginx-matrix-tls
|
||||
EOF
|
||||
}
|
||||
|
||||
ansible_wrap() {
|
||||
local inv="${ANSIBLE_INVENTORY:-${ROOT}/ansible/inventory.ini}"
|
||||
[[ -f "$inv" ]] || { echo "[ERR] inventory 不存在:$inv" >&2; exit 1; }
|
||||
command -v ansible-playbook >/dev/null 2>&1 || { echo "[ERR] 未找到 ansible-playbook" >&2; exit 1; }
|
||||
ansible_lab_check_inventory_keys "$inv" || exit 1
|
||||
local td="${DEPLOY_VERIFY_TEARDOWN:-0}"
|
||||
echo "[RUN] ansible-playbook -i $inv -e VERIFY_TEARDOWN=$td $*"
|
||||
ansible-playbook -i "$inv" -e "VERIFY_TEARDOWN=$td" "$@"
|
||||
}
|
||||
|
||||
cmd_k3s() {
|
||||
if [[ "${K3S_PREPARE_STORAGE:-false}" == "true" ]]; then
|
||||
ansible_wrap "${ROOT}/ansible/playbooks/verify/01-05.yml" -e 'k3s_do_prepare_storage=true' -e 'k3s_prepare_storage=true'
|
||||
fi
|
||||
ansible_wrap "${ROOT}/ansible/playbooks/verify/01-05.yml" -e 'k3s_do_install=true'
|
||||
}
|
||||
|
||||
main() {
|
||||
load_env
|
||||
local sub="${1:-}"
|
||||
case "$sub" in
|
||||
""|-h|--help) usage ;;
|
||||
k3s) cmd_k3s ;;
|
||||
longhorn) ansible_wrap "${ROOT}/ansible/playbooks/verify/03-07.yml" ;;
|
||||
nginx-matrix) ansible_wrap "${ROOT}/ansible/playbooks/verify/02-05.yml" ;;
|
||||
nginx-matrix-tls) ansible_wrap "${ROOT}/ansible/playbooks/verify/03-02.yml" -e 'nginx_matrix_tls_enable=true' ;;
|
||||
*) echo "[ERR] 未知子命令:$sub" >&2; usage; exit 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
main "$@"
|
||||
Reference in New Issue
Block a user