fix: bootstrap tailscale on recreated OCI edge

This commit is contained in:
juvenal.diaz 2026-10-26 21:14:21 -06:00
parent ce2d09399a
commit 4e9631dc71
4 changed files with 84 additions and 59 deletions

View File

@ -182,6 +182,7 @@ set -eu
install_dir="${self.triggers.install_dir}" install_dir="${self.triggers.install_dir}"
install_docker="${self.triggers.install_docker}" install_docker="${self.triggers.install_docker}"
tailscale_auth_key='${var.edge_tailscale_auth_key}'
server_name="${self.triggers.server_name}" server_name="${self.triggers.server_name}"
server_names="${self.triggers.server_names}" server_names="${self.triggers.server_names}"
certbot_domain_args="${self.triggers.certbot_domain_args}" certbot_domain_args="${self.triggers.certbot_domain_args}"
@ -218,6 +219,21 @@ install_missing_packages() {
install_missing_packages ca-certificates curl openssl prometheus-node-exporter install_missing_packages ca-certificates curl openssl prometheus-node-exporter
sudo systemctl enable --now prometheus-node-exporter sudo systemctl enable --now prometheus-node-exporter
if ! command -v tailscale >/dev/null 2>&1; then
curl -fsSL https://tailscale.com/install.sh | sudo sh
fi
if ! tailscale ip -4 >/dev/null 2>&1; then
if [ -z "$tailscale_auth_key" ]; then
echo "Tailscale is not connected on the edge VM. Set LAB_EDGE_TAILSCALE_AUTH_KEY for a fresh edge bootstrap." >&2
exit 1
fi
sudo tailscale up --auth-key "$tailscale_auth_key" --hostname homelab-oci-edge --accept-routes
fi
if ! tailscale ip -4 >/dev/null 2>&1; then
echo "Tailscale did not obtain an IPv4 address on the edge VM." >&2
exit 1
fi
if ! curl -fsS --connect-timeout 10 -H "Host: $server_name" "http://$backend_host:$backend_port/" >/dev/null; then if ! curl -fsS --connect-timeout 10 -H "Host: $server_name" "http://$backend_host:$backend_port/" >/dev/null; then
echo "Warning: cannot reach Traefik backend http://$backend_host:$backend_port/ for $server_name from the edge host." >&2 echo "Warning: cannot reach Traefik backend http://$backend_host:$backend_port/ for $server_name from the edge host." >&2
echo "The edge proxy will still be deployed so independent routes such as /git/ can recover." >&2 echo "The edge proxy will still be deployed so independent routes such as /git/ can recover." >&2

View File

@ -23,6 +23,13 @@ variable "edge_install_dir" {
default = "/opt/homelab-edge" default = "/opt/homelab-edge"
} }
variable "edge_tailscale_auth_key" {
description = "Ephemeral Tailscale auth key used to join a newly recreated OCI edge VM. Never persist this value in Terraform state or inventory."
type = string
sensitive = true
default = ""
}
variable "edge_install_docker" { variable "edge_install_docker" {
type = bool type = bool
default = false default = false

View File

@ -269,6 +269,7 @@ export_homelab_inventory_tf_vars() {
export_if_unset TF_VAR_edge_host "${LAB_EDGE_HOST:-}" export_if_unset TF_VAR_edge_host "${LAB_EDGE_HOST:-}"
export_if_unset TF_VAR_edge_user "${LAB_EDGE_USER:-}" export_if_unset TF_VAR_edge_user "${LAB_EDGE_USER:-}"
export_if_unset TF_VAR_edge_install_dir "${LAB_EDGE_INSTALL_DIR:-}" export_if_unset TF_VAR_edge_install_dir "${LAB_EDGE_INSTALL_DIR:-}"
export_if_unset TF_VAR_edge_tailscale_auth_key "${LAB_EDGE_TAILSCALE_AUTH_KEY:-}"
export_if_unset TF_VAR_server_name "${LAB_DOMAIN:-}" 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_additional_server_names "${LAB_ADDITIONAL_SERVER_NAMES_JSON:-}"
export_if_unset TF_VAR_jeannie_api_metrics_target "${LAB_JEANNIE_API_METRICS_TARGET:-api.${LAB_DOMAIN:-lab2025.duckdns.org}:443}" export_if_unset TF_VAR_jeannie_api_metrics_target "${LAB_JEANNIE_API_METRICS_TARGET:-api.${LAB_DOMAIN:-lab2025.duckdns.org}:443}"

View File

@ -225,6 +225,7 @@ export_homelab_inventory_tf_vars() {
export_if_unset TF_VAR_edge_host "${LAB_EDGE_HOST:-}" export_if_unset TF_VAR_edge_host "${LAB_EDGE_HOST:-}"
export_if_unset TF_VAR_edge_user "${LAB_EDGE_USER:-}" export_if_unset TF_VAR_edge_user "${LAB_EDGE_USER:-}"
export_if_unset TF_VAR_edge_install_dir "${LAB_EDGE_INSTALL_DIR:-}" export_if_unset TF_VAR_edge_install_dir "${LAB_EDGE_INSTALL_DIR:-}"
export_if_unset TF_VAR_edge_tailscale_auth_key "${LAB_EDGE_TAILSCALE_AUTH_KEY:-}"
export_if_unset TF_VAR_server_name "${LAB_DOMAIN:-}" 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_additional_server_names "${LAB_ADDITIONAL_SERVER_NAMES_JSON:-}"
export_if_unset TF_VAR_jeannie_api_metrics_target "${LAB_JEANNIE_API_METRICS_TARGET:-api.${LAB_DOMAIN:-lab2025.duckdns.org}:443}" export_if_unset TF_VAR_jeannie_api_metrics_target "${LAB_JEANNIE_API_METRICS_TARGET:-api.${LAB_DOMAIN:-lab2025.duckdns.org}:443}"