feat: add script to apply DNS manifests via SSH and kubectl
This commit is contained in:
@@ -1,38 +1,35 @@
|
||||
import paramiko
|
||||
import sys
|
||||
import time
|
||||
|
||||
sys.stdout.reconfigure(encoding='utf-8')
|
||||
SSH_KEY = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet"
|
||||
|
||||
key_path = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet"
|
||||
|
||||
def apply_to_cluster(ip, name, manifest_path):
|
||||
print(f"Connecting to {name} ({ip})...")
|
||||
with open(manifest_path, "r", encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
c = paramiko.SSHClient()
|
||||
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
c.connect(ip, username="root", key_filename=key_path, timeout=10)
|
||||
def apply_manifest(host, local_file):
|
||||
with open(local_file, "r") as f:
|
||||
manifest_content = f.read()
|
||||
|
||||
stdin, stdout, stderr = c.exec_command("k3s kubectl apply -f -")
|
||||
stdin.write(content)
|
||||
stdin.channel.shutdown_write()
|
||||
client = paramiko.SSHClient()
|
||||
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
client.connect(host, username="root", key_filename=SSH_KEY, timeout=10)
|
||||
|
||||
out = stdout.read().decode('utf-8')
|
||||
err = stderr.read().decode('utf-8')
|
||||
print(f"[{name}] Apply Output:\n{out}")
|
||||
if err.strip():
|
||||
print(f"[{name}] Apply Error:\n{err}")
|
||||
c.close()
|
||||
|
||||
aero_path = r"c:\Users\Snarf\OneDrive\Desktop\code\SnarfCode\homelab-gitops-repo\manifests\aerodrome\dns\dns-stack.yaml"
|
||||
space_path = r"c:\Users\Snarf\OneDrive\Desktop\code\SnarfCode\homelab-gitops-repo\manifests\spaceport\dns\dns-stack.yaml"
|
||||
|
||||
apply_to_cluster("140.44.4.11", "Aerodrome", aero_path)
|
||||
time.sleep(2)
|
||||
apply_to_cluster("140.44.4.41", "Spaceport", space_path)
|
||||
print("Finished applying manifests to both clusters!")
|
||||
|
||||
# Write to remote /tmp/dns-stack.yaml and kubectl apply
|
||||
sftp = client.open_sftp()
|
||||
with sftp.open("/tmp/dns-stack.yaml", "w") as f:
|
||||
f.write(manifest_content)
|
||||
sftp.close()
|
||||
|
||||
stdin, stdout, stderr = client.exec_command("k3s kubectl apply -f /tmp/dns-stack.yaml")
|
||||
out = stdout.read().decode()
|
||||
err = stderr.read().decode()
|
||||
client.close()
|
||||
return out, err
|
||||
|
||||
print("=== Applying to Aerodrome (140.44.4.11) ===")
|
||||
out, err = apply_manifest("140.44.4.11", r"homelab-gitops-repo\manifests\aerodrome\dns\dns-stack.yaml")
|
||||
print(out)
|
||||
if err:
|
||||
print("Stderr:", err)
|
||||
|
||||
print("=== Applying to Spaceport (140.44.4.41) ===")
|
||||
out, err = apply_manifest("140.44.4.41", r"homelab-gitops-repo\manifests\spaceport\dns\dns-stack.yaml")
|
||||
print(out)
|
||||
if err:
|
||||
print("Stderr:", err)
|
||||
|
||||
Reference in New Issue
Block a user