feat: add boot staging configuration and automation utility scripts
This commit is contained in:
58
scripts/sync_and_launch_awx.py
Normal file
58
scripts/sync_and_launch_awx.py
Normal file
@@ -0,0 +1,58 @@
|
||||
import paramiko, time
|
||||
|
||||
ssh = paramiko.SSHClient()
|
||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
ssh.connect('140.44.4.11', username='root', key_filename=r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet', timeout=10)
|
||||
|
||||
py_code = """
|
||||
from awx.main.models import Project, JobTemplate, Job
|
||||
import time
|
||||
|
||||
# 1. Update project
|
||||
p = Project.objects.get(name='Snarfnet Infrastructure Playbooks')
|
||||
update = p.update()
|
||||
print(f"Triggered project update [{update.id}]...")
|
||||
|
||||
# Wait for project update
|
||||
for _ in range(12):
|
||||
update.refresh_from_db()
|
||||
if update.status in ['successful', 'failed', 'error']:
|
||||
break
|
||||
time.sleep(2)
|
||||
|
||||
print(f"Project update [{update.id}] finished: Status={update.status}")
|
||||
if update.status != 'successful':
|
||||
print("Project update failed! Aborting.")
|
||||
exit(1)
|
||||
|
||||
# 2. Launch Job Template
|
||||
jt = JobTemplate.objects.get(name='Daily Drift & Agent Health Audit')
|
||||
job = jt.create_unified_job()
|
||||
job.signal_start()
|
||||
print(f"Launched Job [{job.id}] for '{jt.name}': Status={job.status}")
|
||||
|
||||
# 3. Poll for completion
|
||||
for _ in range(40):
|
||||
job.refresh_from_db()
|
||||
if job.status in ['successful', 'failed', 'error', 'canceled']:
|
||||
break
|
||||
time.sleep(3)
|
||||
|
||||
print(f"Job [{job.id}] finished with Status={job.status}, Elapsed={job.elapsed}s, Failed={job.failed}")
|
||||
|
||||
# 4. Print events / recap
|
||||
print("\n=== JOB RECAP / OUTPUT ===")
|
||||
events = job.job_events.order_by('id')
|
||||
for e in events:
|
||||
if e.stdout:
|
||||
print(e.stdout)
|
||||
"""
|
||||
|
||||
cmd = f"kubectl exec -i -n awx -c awx-task deployment/awx-task -- awx-manage shell_plus --quiet << 'EOF'\n{py_code}\nEOF"
|
||||
stdin, stdout, stderr = ssh.exec_command(cmd)
|
||||
|
||||
for line in iter(stdout.readline, ""):
|
||||
print(line, end="")
|
||||
|
||||
ssh.close()
|
||||
|
||||
Reference in New Issue
Block a user