import os new_configmap_data = """apiVersion: v1 data: bookmarks.yaml: | - Developer: - Github: - abbr: GH href: https://github.com/ docker.yaml: '' kubernetes.yaml: | mode: disable services.yaml: | - Critical Services: - Authentik: icon: authentik.png href: https://authentik.snarfnet.net widget: type: authentik url: https://authentik.snarfnet.net fields: ["users", "loginsLast24H", "failedLoginsLast24H"] key: 7HamapUhYizcNudHDIT5IFy3XEpRgeKgqr1Pw4ub9eTpAjMAzB8Aur1Z6dUU - PeaNUT UPS: icon: peanut.png href: https://portal.snarfnet.net widget: type: peanut url: https://peanut.snarfnet.net fields: ["battery_charge", "ups_load", "ups_status"] key: server-closet - Unifi Controller: icon: unifi.png href: https://unifi.ui.com widget: type: unifi url: https://140.44.44.1 username: Snarf password: Katzir476!!! - GitOps & Automation: - Gitea: icon: gitea.png href: https://git.snarfnet.net widget: type: gitea url: https://git.snarfnet.net fields: ["repositories", "notifications", "issues", "pulls"] key: 47c10c54574131c007302b246352f653facb5062 - ArgoCD: icon: argocd.png href: https://argo.snarfnet.net - AWX Automation: icon: awx.png href: https://awx.snarfnet.net - Semaphore: icon: semaphore.png href: https://semaphore.snarfnet.net - Storage & Clusters: - Longhorn Aerodrome: icon: longhorn.png href: https://longhorn.aerodrome.snarfnet.net widget: type: longhorn url: https://longhorn.aerodrome.snarfnet.net - Longhorn Spaceport: icon: longhorn.png href: https://longhorn.spaceport.snarfnet.net widget: type: longhorn url: https://longhorn.spaceport.snarfnet.net - Rancher (Aerodrome): icon: rancher.png href: https://aerodrome.snarfnet.net widget: type: rancher url: https://aerodrome.snarfnet.net cluster: local - Harvester HCI (Spacedock): icon: harvester.png href: https://harvester.spacedock.snarfnet.net - Portainer Swarm: icon: portainer.png href: https://shipyard.snarfnet.net widget: type: portainer url: https://shipyard.snarfnet.net env: 1 - Infrastructure & Observability: - NGINX Proxy Manager: icon: nginx-proxy-manager href: https://nginx.snarfnet.net widget: type: npm url: https://nginx.snarfnet.net fields: ["enabled", "disabled", "total"] username: snarf@snarfnet.net password: Katzir476! - Uptime Kuma: icon: uptime-kuma href: https://uptime.snarfnet.net widget: type: uptimekuma url: https://uptime.snarfnet.net fields: ["up", "down", "uptime", "incident"] slug: public - Zabbix: icon: zabbix.png href: https://zabbix.snarfnet.net - Grafana: icon: grafana.png href: https://grafana.snarfnet.net - Core Node Glances: icon: glances.png href: http://140.44.4.11:61208 widget: type: glances url: http://140.44.4.11:61208 version: 4 metric: cpu - Environment & Weather: - Tempest Weather Station: icon: weather.png href: https://snarfhome.snarfnet.net description: Backyard Weather Telemetry widget: type: homeassistant url: http://14.4.4.20:8123 key: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIzZWUyNTE1MDk0NGU0ZjRjYmJkMGM1MWI5MThmY2EzYiIsImlhdCI6MTc0NjgxMDM3NSwiZXhwIjoyMDYyMTcwMzc1fQ.Le6M7WL63nxtLTxccFacQR5GVUY5C-a_zGtmXT_uaz4 custom: - state: sensor.tempest_st_temperature label: Outdoor Temp - state: sensor.tempest_st_wind_speed label: Wind Speed - state: sensor.tempest_st_humidity label: Humidity - state: sensor.tempest_st_rain_rate label: Rain Rate settings.yaml: | title: SnarfNet Operations & Telemetry headerStyle: boxedWidgets color: green theme: dark layout: Critical Services: GitOps & Automation: Storage & Clusters: Infrastructure & Observability: Environment & Weather: showStats: true providers: longhorn: url: https://longhorn.aerodrome.snarfnet.net widgets.yaml: | - resources: backend: resources cpu: true expanded: true memory: true - search: provider: duckduckgo target: _blank - longhorn: expanded: true total: true labels: true nodes: true """ filepath = r"homelab-gitops-repo\manifests\spaceport\homepage\homepage.yaml" with open(filepath, "r", encoding="utf-8") as f: text = f.read() # The configmap starts after the second "---" delimiter parts = text.split("---\n") if len(parts) == 1: parts = text.split("---\r\n") # parts[0] is Deployment, parts[1] is Service, parts[2] is ConfigMap cm_part = parts[2] cm_kind_idx = cm_part.index("kind: ConfigMap") cm_suffix = cm_part[cm_kind_idx:] new_cm_part = new_configmap_data + cm_suffix parts[2] = new_cm_part new_full = "---\n".join(parts) with open(filepath, "w", encoding="utf-8", newline="\r\n") as f: f.write(new_full) print("Updated homepage.yaml cleanly!")