Files
HetznerTerra/ansible/generate_inventory.py
MichaelFisher1997 ff31cb4e74
Some checks failed
Deploy Cluster / Terraform (push) Failing after 10s
Deploy Cluster / Ansible (push) Has been skipped
Implement HA control plane with Load Balancer (3-3 topology)
Major changes:
- Terraform: Scale to 3 control planes (cx23) + 3 workers (cx33)
- Terraform: Add Hetzner Load Balancer (lb11) for Kubernetes API
- Terraform: Add kube_api_lb_ip output
- Ansible: Add community.network collection to requirements
- Ansible: Update inventory to include LB endpoint
- Ansible: Configure secondary CPs and workers to join via LB
- Ansible: Add k3s_join_endpoint variable for HA joins
- Workflow: Add imports for cp-2, cp-3, and worker-3
- Docs: Update STABLE_BASELINE.md with HA topology and phase gates

Topology:
- 3 control planes (cx23 - 2 vCPU, 8GB RAM each)
- 3 workers (cx33 - 4 vCPU, 16GB RAM each)
- 1 Load Balancer (lb11) routing to all 3 control planes on port 6443
- Workers and secondary CPs join via LB endpoint for HA

Cost impact: +~€26/month (2 extra CPs + 1 extra worker + LB)
2026-03-23 02:39:39 +00:00

76 lines
2.0 KiB
Python

#!/usr/bin/env python3
import json
import subprocess
import sys
from pathlib import Path
from jinja2 import Environment, FileSystemLoader
def get_terraform_outputs():
result = subprocess.run(
["terraform", "output", "-json"],
cwd="../terraform",
capture_output=True,
text=True,
)
if result.returncode != 0:
print(f"Error running terraform output: {result.stderr}")
sys.exit(1)
return json.loads(result.stdout)
def main():
outputs = get_terraform_outputs()
control_plane_names = outputs["control_plane_names"]["value"]
control_plane_ips = outputs["control_plane_ips"]["value"]
control_plane_private_ips = outputs["control_plane_private_ips"]["value"]
worker_names = outputs["worker_names"]["value"]
worker_ips = outputs["worker_ips"]["value"]
worker_private_ips = outputs["worker_private_ips"]["value"]
kube_api_lb_ip = outputs.get("kube_api_lb_ip", {}).get("value", control_plane_ips[0])
control_planes = [
{
"name": name,
"public_ip": public_ip,
"private_ip": private_ip,
}
for name, public_ip, private_ip in zip(
control_plane_names, control_plane_ips, control_plane_private_ips
)
]
workers = [
{
"name": name,
"public_ip": public_ip,
"private_ip": private_ip,
}
for name, public_ip, private_ip in zip(
worker_names, worker_ips, worker_private_ips
)
]
data = {
"control_planes": control_planes,
"workers": workers,
"private_key_file": outputs["ssh_private_key_path"]["value"],
"kube_api_lb_ip": kube_api_lb_ip,
}
env = Environment(loader=FileSystemLoader("."))
template = env.get_template("inventory.tmpl")
inventory = template.render(**data)
Path("inventory.ini").write_text(inventory)
print("Generated inventory.ini")
if __name__ == "__main__":
main()