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