import paramiko import yaml c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect('140.44.4.11', username='root', key_filename=r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet', timeout=10) with open(r'c:\Users\Snarf\OneDrive\Desktop\code\SnarfCode\homelab-gitops-repo\manifests\aerodrome\prometheus\prometheus.yaml', 'r') as f: docs = list(yaml.safe_load_all(f)) # Find ConfigMap prometheus-config cm_doc = None for d in docs: if d and d.get('kind') == 'ConfigMap' and d.get('metadata', {}).get('name') == 'prometheus-config': cm_doc = d break if cm_doc: cm_yaml = yaml.dump(cm_doc) stdin, stdout, stderr = c.exec_command("cat > /tmp/prometheus_cm.yaml") stdin.write(cm_yaml) stdin.close() stdout.channel.recv_exit_status() _, o, e = c.exec_command("kubectl apply -f /tmp/prometheus_cm.yaml") print("CM apply:\n", o.read().decode().strip()) err = e.read().decode().strip() if err: print("CM err:", err) # Restart prometheus pod _, o, _ = c.exec_command("kubectl rollout restart deployment/prometheus") print("Prometheus restart:", o.read().decode().strip()) _, o, _ = c.exec_command("kubectl rollout status deployment/prometheus --timeout=60s") print("Rollout status:", o.read().decode().strip()) c.close()