more stuff
This commit is contained in:
parent
6a43132bc8
commit
79e6a1a543
18 changed files with 426 additions and 144 deletions
|
|
@ -58,17 +58,40 @@ record_summary() {
|
|||
}
|
||||
|
||||
get_hosts_from_inventory() {
|
||||
local group="$1"
|
||||
local target="$1"
|
||||
cd "$ANSIBLE_DIR"
|
||||
ansible-inventory -i inventory.ini --list | \
|
||||
python3 -c "import sys, json; data=json.load(sys.stdin); print(' '.join(data.get('$group', {}).get('hosts', [])))" 2>/dev/null || echo ""
|
||||
python3 - "$target" <<'PY' 2>/dev/null || echo ""
|
||||
import json, sys
|
||||
data = json.load(sys.stdin)
|
||||
target = sys.argv[1]
|
||||
if target in data:
|
||||
print(' '.join(data[target].get('hosts', [])))
|
||||
else:
|
||||
hostvars = data.get('_meta', {}).get('hostvars', {})
|
||||
if target in hostvars:
|
||||
print(target)
|
||||
PY
|
||||
}
|
||||
|
||||
get_primary_host_ip() {
|
||||
local group="$1"
|
||||
local target="$1"
|
||||
cd "$ANSIBLE_DIR"
|
||||
ansible-inventory -i inventory.ini --list | \
|
||||
python3 -c "import sys, json; data=json.load(sys.stdin); hosts=data.get('$group', {}).get('hosts', []); print(hosts[0] if hosts else '')" 2>/dev/null || echo ""
|
||||
python3 - "$target" <<'PY' 2>/dev/null || echo ""
|
||||
import json, sys
|
||||
data = json.load(sys.stdin)
|
||||
target = sys.argv[1]
|
||||
hostvars = data.get('_meta', {}).get('hostvars', {})
|
||||
if target in hostvars:
|
||||
print(hostvars[target].get('ansible_host', target))
|
||||
else:
|
||||
hosts = data.get(target, {}).get('hosts', [])
|
||||
if hosts:
|
||||
first = hosts[0]
|
||||
hv = hostvars.get(first, {})
|
||||
print(hv.get('ansible_host', first))
|
||||
PY
|
||||
}
|
||||
|
||||
check_prerequisites() {
|
||||
|
|
@ -112,14 +135,14 @@ check_prerequisites() {
|
|||
print_success "services_config.yml exists"
|
||||
fi
|
||||
|
||||
if ! grep -q "^\[vipy\]" "$ANSIBLE_DIR/inventory.ini"; then
|
||||
if [ -z "$(get_hosts_from_inventory "vipy")" ]; then
|
||||
print_error "vipy not configured in inventory.ini"
|
||||
((errors++))
|
||||
else
|
||||
print_success "vipy configured in inventory"
|
||||
fi
|
||||
|
||||
if ! grep -q "^\[memos-box\]" "$ANSIBLE_DIR/inventory.ini"; then
|
||||
if [ -z "$(get_hosts_from_inventory "memos-box")" ]; then
|
||||
print_warning "memos-box not configured in inventory.ini (memos deployment will be skipped)"
|
||||
else
|
||||
print_success "memos-box configured in inventory"
|
||||
|
|
@ -173,8 +196,9 @@ check_dns_configuration() {
|
|||
fi
|
||||
|
||||
local memos_ip=""
|
||||
if grep -q "^\[memos-box\]" "$ANSIBLE_DIR/inventory.ini"; then
|
||||
memos_ip=$(get_primary_host_ip "memos-box")
|
||||
local memos_host=$(get_hosts_from_inventory "memos-box")
|
||||
if [ -n "$memos_host" ]; then
|
||||
memos_ip=$(get_primary_host_ip "$memos_host")
|
||||
fi
|
||||
|
||||
local dns_ok=true
|
||||
|
|
@ -262,7 +286,7 @@ deploy_ntfy_emergency_app() {
|
|||
deploy_memos() {
|
||||
print_header "Deploying Memos"
|
||||
|
||||
if ! grep -q "^\[memos-box\]" "$ANSIBLE_DIR/inventory.ini"; then
|
||||
if [ -z "$(get_hosts_from_inventory "memos-box")" ]; then
|
||||
print_warning "memos-box not in inventory. Skipping memos deployment."
|
||||
record_summary "${YELLOW}• memos${NC}: skipped (memos-box missing)"
|
||||
return 0
|
||||
|
|
@ -311,19 +335,16 @@ verify_services() {
|
|||
echo ""
|
||||
fi
|
||||
|
||||
if grep -q "^\[memos-box\]" "$ANSIBLE_DIR/inventory.ini"; then
|
||||
local memos_host
|
||||
memos_host=$(get_hosts_from_inventory "memos-box")
|
||||
|
||||
if [ -n "$memos_host" ]; then
|
||||
print_info "Checking memos on memos-box ($memos_host)..."
|
||||
if timeout 5 ssh -i "$ssh_key" -o StrictHostKeyChecking=no -o BatchMode=yes counterweight@$memos_host "systemctl is-active memos" &>/dev/null; then
|
||||
print_success "memos systemd service running"
|
||||
else
|
||||
print_warning "memos systemd service not running"
|
||||
fi
|
||||
echo ""
|
||||
local memos_host
|
||||
memos_host=$(get_hosts_from_inventory "memos-box")
|
||||
if [ -n "$memos_host" ]; then
|
||||
print_info "Checking memos on memos-box ($memos_host)..."
|
||||
if timeout 5 ssh -i "$ssh_key" -o StrictHostKeyChecking=no -o BatchMode=yes counterweight@$memos_host "systemctl is-active memos" &>/dev/null; then
|
||||
print_success "memos systemd service running"
|
||||
else
|
||||
print_warning "memos systemd service not running"
|
||||
fi
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue