Implement reproducible S1 handoff contracts
Assistant: codex Assistant-Model: gpt-5.6-sol Assistant-Session: 01a02994-7685-7940-bf34-3555b8256018
This commit is contained in:
parent
c8cb1c8edf
commit
b93af8cc78
44 changed files with 2035 additions and 342 deletions
|
|
@ -1,16 +1,28 @@
|
|||
#!/usr/bin/env python3
|
||||
import json, yaml, subprocess, os, sys, pathlib, glob
|
||||
|
||||
REPO_ROOT = pathlib.Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(REPO_ROOT / "scripts"))
|
||||
|
||||
from baseline_contract import load_spec, profile_hostvars
|
||||
from inventory_contract import load_inventory
|
||||
|
||||
def load_servers():
|
||||
with open(os.path.join(os.path.dirname(__file__), '..', 'inventory', 'servers.yaml')) as f:
|
||||
data = yaml.safe_load(f)
|
||||
data = load_inventory(REPO_ROOT / 'inventory' / 'servers.yaml')
|
||||
servers = data.get('servers', [])
|
||||
return servers
|
||||
|
||||
def load_baseline():
|
||||
return load_spec(REPO_ROOT / 'spec' / 'server-baseline.yaml')
|
||||
|
||||
def load_tf_outputs():
|
||||
# Try to read terraform outputs to attach IPs, if available.
|
||||
try:
|
||||
out = subprocess.check_output(['terraform', '-chdir=../terraform/hetzner', 'output', '-json'], stderr=subprocess.DEVNULL, text=True)
|
||||
out = subprocess.check_output(
|
||||
['terraform', f'-chdir={REPO_ROOT / "terraform" / "hetzner"}', 'output', '-json'],
|
||||
stderr=subprocess.DEVNULL,
|
||||
text=True,
|
||||
)
|
||||
j = json.loads(out)
|
||||
servers = j.get('servers', {}).get('value', {})
|
||||
return servers # {name: ip}
|
||||
|
|
@ -40,6 +52,7 @@ def load_host_vars(name):
|
|||
|
||||
def main():
|
||||
server_list = load_servers()
|
||||
baseline = load_baseline()
|
||||
tf = load_tf_outputs()
|
||||
host_names = []
|
||||
hostvars = {}
|
||||
|
|
@ -50,6 +63,7 @@ def main():
|
|||
"ansible_host": tf.get(name) or s.get('ip'),
|
||||
"ansible_user": s.get('ssh_user', 'admin'),
|
||||
}
|
||||
hvars.update(profile_hostvars(baseline, s['baseline_profile']))
|
||||
if s.get('ssh_key'):
|
||||
hvars["ansible_ssh_private_key_file"] = s['ssh_key']
|
||||
hvars.update(load_host_vars(name))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue