feat: Add HA Kubernetes cluster with Terraform + Ansible
- 3x CX23 control plane nodes (HA) - 4x CX33 worker nodes - k3s with embedded etcd - Hetzner CCM for load balancers - Gitea CI/CD workflows - Backblaze B2 for Terraform state
This commit is contained in:
45
ansible/generate_inventory.py
Normal file
45
ansible/generate_inventory.py
Normal file
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import json
|
||||
import os
|
||||
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()
|
||||
|
||||
data = {
|
||||
"control_plane_ips": outputs["control_plane_ips"]["value"],
|
||||
"worker_ips": outputs["worker_ips"]["value"],
|
||||
"private_key_file": outputs["ssh_private_key_path"]["value"],
|
||||
}
|
||||
|
||||
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()
|
||||
Reference in New Issue
Block a user