#!/bin/bash # Generiert /etc/dnsmasq.hosts aus dem Ansible Inventory # Usage: ./update-dns.sh [--apply] INI="/app-config/ansible/pfannkuchen.ini" OUT="/etc/dnsmasq.hosts" TMP=$(mktemp) echo "# Auto-generated from pfannkuchen.ini" > "$TMP" echo "# $(date)" >> "$TMP" grep "ansible_host=" "$INI" | while read line; do name=$(echo "$line" | awk '{print $1}') ip=$(echo "$line" | grep -oP 'ansible_host=\K[0-9.]+') [ -n "$ip" ] && echo "$ip $name" >> "$TMP" done if [ "$1" = "--apply" ]; then sudo cp "$TMP" "$OUT" sudo systemctl restart dnsmasq COUNT=$(grep -cP '^\d' "$OUT") echo "✅ ${COUNT} Hosts → dnsmasq aktualisiert" else echo "Preview:" cat "$TMP" echo "" echo "→ Mit --apply übernehmen" fi rm -f "$TMP"