mirror of
https://github.com/dredx/prole.git
synced 2026-09-24 19:34:31 +00:00
Repairs and improvements:
- iSCSI: Added cleanup tasks to remove stale mounts and fstab entries. Improved robustness of iSCSI target management and added 'iscsi_absent_mounts' support.
- K3s:
- Updated service start logic to accept 'activating' state, preventing premature failure during slow startups.
- Improved service stop logic to safely handle missing or not-found services.
- Ensured 'prole-installer' ServiceAccount and ClusterRoleBinding exist for K8s administration.
- Added leader election and etcd tuning arguments (forgiving leases) to config.yaml.j2.
- Removed deprecated 'prole-port-forwards' systemd service.
- Installer & Scripts:
- Updated legacy_tk.py to support K3s mode, secret resolution for passwords, and better environment management (including ~/.prole/env.sh for service mode).
- Updated init_ansible.sh to support PROLE_VAULT_PASS_FILE and ANSIBLE_VAULT_PASSWORD_FILE.
- Improved directory and kubeconfig path resolution in prole_cfg.sh to support fallback to ~/.prole.
- Enhanced Grafana password resolution in init_monitoring.sh.
- Added automatic application of iSCSI StorageClass and PersistentVolumes in init_openbao.sh.
- General: Switched conf/prole.cfg to k3s deployment mode and updated vault_k3s.yml token.
New Ansible Tasks and Playbooks:
- infrastructure/playbooks/iscsi_cleanup.yml: Automates logout and removal of stale iSCSI node records.
- infrastructure/playbooks/prole_logs_migrate.yml: Orchestrates /prole/logs migration to iSCSI storage.
- infrastructure/playbooks/tmp_bao_dir.yml: Ensures host-level storage directories for OpenBao.
- infrastructure/playbooks/tmp_mount.yml: Utility to verify and enforce host-level mounts.
- infrastructure/playbooks/k3s_sync.yml: Added tasks to start K3s after sync and update local kubeconfig on the controller.
- Added 'Unmount stale iSCSI mounts' and 'Remove stale iSCSI fstab entries' to the iscsi role.
- Added 'Ensure prole-installer service account exists' to the k3s role.
112 lines
3.6 KiB
Bash
Executable File
112 lines
3.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
export ANSIBLE_CONFIG="${ROOT_DIR}/ansible.cfg"
|
|
|
|
# Defaults
|
|
MODE="fg" # fg|bg
|
|
PLAYBOOK="infrastructure/playbooks/site.yml"
|
|
VAULT_PASS_FILE="" # optional
|
|
LIMIT="" # optional
|
|
TAGS="" # optional
|
|
EXTRA_ARGS=() # passthrough
|
|
# Use local logs if PROLE_LOGS is not writable or looks like a remote path
|
|
LOG_BASE="${ROOT_DIR}/.ansible/logs"
|
|
if [[ -n "${PROLE_LOGS:-}" ]]; then
|
|
# If it's a relative path, or it exists and is writable, or its parent is writable
|
|
if [[ ! "${PROLE_LOGS}" =~ ^/ ]] || [[ -w "${PROLE_LOGS}" ]] || [[ -w "$(dirname "${PROLE_LOGS}" 2>/dev/null)" ]]; then
|
|
LOG_BASE="${PROLE_LOGS}"
|
|
fi
|
|
fi
|
|
LOG_BASE="${LOG_BASE%/}"
|
|
LOG_DIR="${LOG_BASE}/ansible"
|
|
SYSLOG_HOST="" # e.g. loghost.prole.org
|
|
SYSLOG_PORT="514"
|
|
SYSLOG_TAG="ansible"
|
|
|
|
usage() {
|
|
cat <<EOF
|
|
Usage: ./ansible.sh [options] [-- <extra ansible-playbook args>]
|
|
|
|
Options:
|
|
-p, --playbook PATH Playbook path (default: ${PLAYBOOK})
|
|
-l, --limit HOSTS Limit hosts
|
|
-t, --tags TAGS Tags
|
|
-v, --vault-pass-file FILE Vault password file
|
|
-m, --mode fg|bg Run in foreground or background (default: fg)
|
|
--syslog-host HOST Send start/end markers via UDP syslog to HOST
|
|
--syslog-port PORT Syslog UDP port (default: 514)
|
|
--syslog-tag TAG Syslog tag (default: ansible)
|
|
-h, --help Show help
|
|
|
|
Examples:
|
|
./ansible.sh -l pi.prole.org -t iscsi -v .vault_pass
|
|
./ansible.sh -m bg -p infrastructure/playbooks/site.yml -v .vault_pass
|
|
./ansible.sh --syslog-host loghost.prole.org -m bg -v .vault_pass -- -vv
|
|
EOF
|
|
}
|
|
|
|
send_syslog() {
|
|
local msg="$1"
|
|
if [[ -n "${SYSLOG_HOST}" ]]; then
|
|
# -d = UDP, -n host, -P port
|
|
logger -d -n "${SYSLOG_HOST}" -P "${SYSLOG_PORT}" -t "${SYSLOG_TAG}" -- "${msg}" || true
|
|
fi
|
|
}
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
-p|--playbook) PLAYBOOK="$2"; shift 2 ;;
|
|
-l|--limit) LIMIT="$2"; shift 2 ;;
|
|
-t|--tags) TAGS="$2"; shift 2 ;;
|
|
-v|--vault-pass-file) VAULT_PASS_FILE="$2"; shift 2 ;;
|
|
-m|--mode) MODE="$2"; shift 2 ;;
|
|
--syslog-host) SYSLOG_HOST="$2"; shift 2 ;;
|
|
--syslog-port) SYSLOG_PORT="$2"; shift 2 ;;
|
|
--syslog-tag) SYSLOG_TAG="$2"; shift 2 ;;
|
|
--) shift; EXTRA_ARGS+=("$@"); break ;;
|
|
-h|--help) usage; exit 0 ;;
|
|
*) EXTRA_ARGS+=("$1"); shift ;;
|
|
esac
|
|
done
|
|
|
|
mkdir -p "${LOG_DIR}"
|
|
|
|
ts="$(date +%Y%m%d-%H%M%S)"
|
|
logfile="${LOG_DIR}/ansible-${ts}.log"
|
|
|
|
cmd=(ansible-playbook "${PLAYBOOK}")
|
|
[[ -n "${LIMIT}" ]] && cmd+=("--limit" "${LIMIT}")
|
|
[[ -n "${TAGS}" ]] && cmd+=("--tags" "${TAGS}")
|
|
[[ -n "${VAULT_PASS_FILE}" ]] && cmd+=("--vault-password-file" "${VAULT_PASS_FILE}")
|
|
cmd+=("${EXTRA_ARGS[@]}")
|
|
|
|
send_syslog "START playbook=${PLAYBOOK} limit=${LIMIT:-<none>} tags=${TAGS:-<none>} log=${logfile}"
|
|
|
|
echo "ANSIBLE_CONFIG=${ANSIBLE_CONFIG}"
|
|
echo "LOGFILE=${logfile}"
|
|
echo "CMD: ${cmd[*]}"
|
|
|
|
if [[ "${MODE}" == "fg" ]]; then
|
|
# Stream to terminal and file
|
|
set +e
|
|
"${cmd[@]}" 2>&1 | tee "${logfile}"
|
|
rc=${PIPESTATUS[0]}
|
|
set -e
|
|
else
|
|
# Background: nohup to logfile
|
|
nohup "${cmd[@]}" >"${logfile}" 2>&1 &
|
|
rc=0
|
|
echo "Started in background (pid $!)"
|
|
fi
|
|
|
|
if [[ "${MODE}" == "fg" ]]; then
|
|
if [[ $rc -eq 0 ]]; then
|
|
send_syslog "END OK playbook=${PLAYBOOK} limit=${LIMIT:-<none>} tags=${TAGS:-<none>} log=${logfile}"
|
|
else
|
|
send_syslog "END FAIL rc=${rc} playbook=${PLAYBOOK} limit=${LIMIT:-<none>} tags=${TAGS:-<none>} log=${logfile}"
|
|
fi
|
|
exit $rc
|
|
fi
|