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 " └────────────────────────────────────────────────────────────────────"
# ─── Step 2: Inventory ───────────────────────────────────────────────────────
# ─── Step 2: Inventory (copy from client_template) ────────────────────────────
echo ""
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
echo " ⚠ Inventory already exists at $INVENTORY_DIR — skipping"
echo " ⚠ Inventory already exists at $INVENTORY_DIR — skipping"
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
mkdir -p "$INVENTORY_DIR/group_vars"
cat > "$INVENTORY_DIR/hosts.yml" << HOSTSEOF
---
all:
vars:
client_id: "${CLIENT_ID}"
client_name: "${CLIENT_NAME}"
billing_model: "${BILLING}"
maintenance_window_start: "02:00"
maintenance_window_end: "05:00"
maintenance_window_tz: "UTC"
change_freeze: false
hypervisor_type: "${HYPERVISOR}"
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"
# Copy the entire template structure
cp -r "$TEMPLATE_DIR/" "$INVENTORY_DIR/"
# Replace placeholders in all copied YAML files
find "$INVENTORY_DIR" -type f \( -name "*.yml" -o -name "*.yaml" \) -exec sed -i \
-e "s/{{ client_id }}/${CLIENT_ID}/g" \
-e "s/{{ client_name }}/${CLIENT_NAME}/g" \
-e "s/{{ client_slug }}/${CLIENT_SLUG}/g" \
-e "s/{{ billing_model }}/${BILLING}/g" \
-e "s/{{ vpn_type }}/${VPN}/g" \
-e "s/{{ hypervisor_type }}/${HYPERVISOR}/g" \
{} \;
echo " Inventory created from template at $INVENTORY_DIR"
fi
# ─── Step 3: Commit to Gitea ─────────────────────────────────────────────────