refactor: resolve external service endpoints from inventory
This commit is contained in:
parent
97ef45a0be
commit
85e7df2927
|
|
@ -47,6 +47,10 @@ Provisioning host: ${LAB_CLUSTER_PROVISIONING_HOST:-${LAB_DEBIAN_LAN_IP:-}}
|
|||
Provisioning user: ${LAB_CLUSTER_PROVISIONING_USER:-${LAB_DEBIAN_USER:-}}
|
||||
GitOps repo URL: ${LAB_GITOPS_REPO_URL:-}
|
||||
Calico operator node: ${LAB_CALICO_OPERATOR_NODE_NAME:-${LAB_CLUSTER_CONTROL_PLANE_NODE_NAME:-}}
|
||||
External services host: ${LAB_SERVICES_HOST:-debian} (${LAB_SERVICES_HOST_LAN_IP:-${LAB_DEBIAN_LAN_IP:-}}, tailscale ${LAB_SERVICES_HOST_TAILSCALE_IP:-${LAB_DEBIAN_TAILSCALE_IP:-}})
|
||||
Gitea backend host: ${LAB_GITEA_BACKEND_HOST:-${LAB_GITEA_TAILSCALE_IP:-${LAB_GITEA_HOST:-}}}
|
||||
Dex backend host: ${LAB_DEX_BACKEND_HOST:-${LAB_DEBIAN_TAILSCALE_IP:-}}
|
||||
Ollama URL: ${LAB_OLLAMA_URL:-http://${LAB_DEBIAN_LAN_IP:-}:11434}
|
||||
Pimox host: ${LAB_CLUSTER_PIMOX_USER:-${LAB_PIMOX_USER:-}}@${LAB_CLUSTER_PIMOX_HOST:-${LAB_PIMOX_HOST:-}}
|
||||
Pimox bridge: ${LAB_CLUSTER_PIMOX_BRIDGE:-${LAB_PIMOX_BRIDGE:-}}
|
||||
Pimox storage: ${LAB_CLUSTER_PIMOX_STORAGE:-${LAB_PIMOX_WORKER_STORAGE:-}}
|
||||
|
|
|
|||
|
|
@ -56,6 +56,8 @@ mapping = {
|
|||
"services.dex.public_url": "LAB_DEX_PUBLIC_URL",
|
||||
"services.jellyfin.http_port": "LAB_JELLYFIN_HTTP_PORT",
|
||||
"services.jellyfin.public_url": "LAB_JELLYFIN_PUBLIC_URL",
|
||||
"services.local_registry.endpoint": "LAB_REGISTRY_ENDPOINT",
|
||||
"services.ollama.url": "LAB_OLLAMA_URL",
|
||||
"services.ollama.bind_address": "LAB_OLLAMA_BIND_ADDRESS",
|
||||
"services.ollama.models_dir": "LAB_OLLAMA_MODELS_DIR",
|
||||
"services.ollama.igpu_enable": "LAB_OLLAMA_IGPU_ENABLE",
|
||||
|
|
@ -162,15 +164,51 @@ for relative_path, (env_name, fallback_path) in profile_mapping.items():
|
|||
if value:
|
||||
print(f": ${{{env_name}:={shlex.quote(value)}}}")
|
||||
|
||||
debian_ip = values.get("hosts.debian.lan_ip")
|
||||
def host_value(host_key, address_kind="lan_ip"):
|
||||
if not host_key:
|
||||
return ""
|
||||
return values.get(f"hosts.{host_key}.{address_kind}", "")
|
||||
|
||||
|
||||
def service_host_key(service_name):
|
||||
return values.get(f"services.{service_name}.host", "")
|
||||
|
||||
|
||||
def service_host_value(service_name, address_kind="lan_ip"):
|
||||
return host_value(service_host_key(service_name), address_kind)
|
||||
|
||||
|
||||
def print_default(env_name, value):
|
||||
if value:
|
||||
print(f": ${{{env_name}:={shlex.quote(value)}}}")
|
||||
|
||||
|
||||
services_host = service_host_key("gitea") or "debian"
|
||||
services_host_lan = host_value(services_host, "lan_ip")
|
||||
services_host_tailscale = host_value(services_host, "tailscale_ip")
|
||||
print_default("LAB_SERVICES_HOST", services_host)
|
||||
print_default("LAB_SERVICES_HOST_LAN_IP", services_host_lan)
|
||||
print_default("LAB_SERVICES_HOST_TAILSCALE_IP", services_host_tailscale)
|
||||
|
||||
gitea_lan = service_host_value("gitea", "lan_ip") or services_host_lan
|
||||
gitea_tailscale = service_host_value("gitea", "tailscale_ip") or services_host_tailscale
|
||||
gitea_http = values.get("services.gitea.http_port")
|
||||
if debian_ip:
|
||||
print(f": ${{LAB_GITEA_HOST:={shlex.quote(debian_ip)}}}")
|
||||
if debian_ip and gitea_http:
|
||||
print(f": ${{LAB_GITEA_LOCAL_URL:={shlex.quote(f'http://{debian_ip}:{gitea_http}/')}}}")
|
||||
gitea_ts = values.get("hosts.debian.tailscale_ip")
|
||||
if gitea_ts:
|
||||
print(f": ${{LAB_GITEA_TAILSCALE_IP:={shlex.quote(gitea_ts)}}}")
|
||||
print_default("LAB_GITEA_HOST", gitea_lan)
|
||||
if gitea_lan and gitea_http:
|
||||
print_default("LAB_GITEA_LOCAL_URL", f"http://{gitea_lan}:{gitea_http}/")
|
||||
print_default("LAB_GITEA_TAILSCALE_IP", gitea_tailscale)
|
||||
print_default("LAB_GITEA_BACKEND_HOST", gitea_tailscale or gitea_lan)
|
||||
|
||||
for service_name, env_name in [
|
||||
("heimdall", "LAB_HEIMDALL_BACKEND_HOST"),
|
||||
("homepage", "LAB_HOMEPAGE_BACKEND_HOST"),
|
||||
("dex", "LAB_DEX_BACKEND_HOST"),
|
||||
("jellyfin", "LAB_JELLYFIN_BACKEND_HOST"),
|
||||
]:
|
||||
service_lan = service_host_value(service_name, "lan_ip") or services_host_lan
|
||||
service_tailscale = service_host_value(service_name, "tailscale_ip") or services_host_tailscale
|
||||
print_default(env_name, service_tailscale or service_lan)
|
||||
|
||||
subdomains = values.get("domain.subdomains")
|
||||
if subdomains:
|
||||
if isinstance(subdomains, str):
|
||||
|
|
@ -226,7 +264,7 @@ export_homelab_inventory_tf_vars() {
|
|||
export_if_unset TF_VAR_server_name "${LAB_DOMAIN:-}"
|
||||
export_if_unset TF_VAR_additional_server_names "${LAB_ADDITIONAL_SERVER_NAMES_JSON:-}"
|
||||
export_if_unset TF_VAR_backend_host "${LAB_TRAEFIK_LB_IP:-}"
|
||||
export_if_unset TF_VAR_gitea_backend_host "${LAB_DEBIAN_TAILSCALE_IP:-}"
|
||||
export_if_unset TF_VAR_gitea_backend_host "${LAB_GITEA_BACKEND_HOST:-${LAB_DEBIAN_TAILSCALE_IP:-}}"
|
||||
export_if_unset TF_VAR_gitea_backend_port "${LAB_GITEA_HTTP_PORT:-}"
|
||||
export_if_unset TF_VAR_heimdall_backend_host "${LAB_HEIMDALL_BACKEND_HOST:-${LAB_DEBIAN_TAILSCALE_IP:-}}"
|
||||
export_if_unset TF_VAR_heimdall_backend_port "${LAB_HEIMDALL_HTTP_PORT:-}"
|
||||
|
|
|
|||
Loading…
Reference in New Issue