Updated to remove heredoc and use template folder.

This commit is contained in:
2026-04-28 10:36:25 -07:00
parent 3e91c3a091
commit 6bbe2ea6d2

View File

@@ -224,62 +224,36 @@ echo " │"
echo " │" echo " │"
echo " └────────────────────────────────────────────────────────────────────" echo " └────────────────────────────────────────────────────────────────────"
# ─── Step 2: Inventory ─────────────────────────────────────────────────────── # ─── Step 2: Inventory (copy from client_template) ────────────────────────────
echo "" echo ""
echo "[ 2 ] Inventory..." echo "[ 2 ] Inventory..."
TEMPLATE_DIR="$REPO_DIR/inventories/client_template"
if [[ ! -d "$TEMPLATE_DIR" ]]; then
echo " ERROR: Template directory not found at $TEMPLATE_DIR"
exit 1
fi
if [[ -d "$INVENTORY_DIR" && ! $UPDATE_MODE ]]; then if [[ -d "$INVENTORY_DIR" && ! $UPDATE_MODE ]]; then
echo " ⚠ Inventory already exists at $INVENTORY_DIR — skipping" echo " ⚠ Inventory already exists at $INVENTORY_DIR — skipping"
elif $DRY_RUN; then elif $DRY_RUN; then
echo " [dry-run] Would create inventory at $INVENTORY_DIR" echo " [dry-run] Would copy inventory from $TEMPLATE_DIR to $INVENTORY_DIR"
else else
mkdir -p "$INVENTORY_DIR/group_vars" # Copy the entire template structure
cp -r "$TEMPLATE_DIR/" "$INVENTORY_DIR/"
cat > "$INVENTORY_DIR/hosts.yml" << HOSTSEOF
--- # Replace placeholders in all copied YAML files
all: find "$INVENTORY_DIR" -type f \( -name "*.yml" -o -name "*.yaml" \) -exec sed -i \
vars: -e "s/{{ client_id }}/${CLIENT_ID}/g" \
client_id: "${CLIENT_ID}" -e "s/{{ client_name }}/${CLIENT_NAME}/g" \
client_name: "${CLIENT_NAME}" -e "s/{{ client_slug }}/${CLIENT_SLUG}/g" \
billing_model: "${BILLING}" -e "s/{{ billing_model }}/${BILLING}/g" \
maintenance_window_start: "02:00" -e "s/{{ vpn_type }}/${VPN}/g" \
maintenance_window_end: "05:00" -e "s/{{ hypervisor_type }}/${HYPERVISOR}/g" \
maintenance_window_tz: "UTC" {} \;
change_freeze: false
hypervisor_type: "${HYPERVISOR}" echo " Inventory created from template at $INVENTORY_DIR"
vpn_type: "${VPN}"
auto_reboot: false
human_estimate_seconds: ${ESTIMATE}
children:
linux_hosts:
hosts: {}
vars:
ansible_user: root
os_family: "debian"
windows_hosts:
hosts: {}
vars:
ansible_user: Administrator
ansible_connection: winrm
ansible_winrm_transport: ntlm
ansible_winrm_server_cert_validation: validate
ansible_port: 5986
HOSTSEOF
cat > "$INVENTORY_DIR/group_vars/all.yml" << VARSEOF
---
# Client: ${CLIENT_NAME} (${CLIENT_ID})
# Onboarded: $(date +%Y-%m-%d)
# Type: ${CLIENT_TYPE}
# VPN: ${VPN}
# Billing: ${BILLING}
# Add client-specific overrides below
VARSEOF
echo " ✓ Inventory created at $INVENTORY_DIR"
fi fi
# ─── Step 3: Commit to Gitea ───────────────────────────────────────────────── # ─── Step 3: Commit to Gitea ─────────────────────────────────────────────────