51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
import json, ssl, urllib.request
|
|
|
|
ctx = ssl.create_default_context()
|
|
ctx.check_hostname = False
|
|
ctx.verify_mode = ssl.CERT_NONE
|
|
|
|
AWX_URL = "http://140.44.4.30:87/api/v2"
|
|
ADMIN_USER = "admin"
|
|
ADMIN_PASS = "CKFj2RfRzNcIeNJIimoW2uZ9En25P4VL"
|
|
|
|
import base64
|
|
auth_header = "Basic " + base64.b64encode(f"{ADMIN_USER}:{ADMIN_PASS}".encode()).decode()
|
|
|
|
def awx_get(endpoint):
|
|
req = urllib.request.Request(f"{AWX_URL}/{endpoint}/", headers={"Authorization": auth_header})
|
|
with urllib.request.urlopen(req, timeout=10, context=ctx) as r:
|
|
return json.loads(r.read().decode())
|
|
|
|
try:
|
|
me = awx_get("me")
|
|
print("AWX Auth Success! User:", me["results"][0]["username"])
|
|
|
|
orgs = awx_get("organizations")
|
|
print(f"\nOrganizations ({orgs['count']}):")
|
|
for o in orgs["results"]:
|
|
print(f" - [{o['id']}] {o['name']}")
|
|
|
|
creds = awx_get("credentials")
|
|
print(f"\nCredentials ({creds['count']}):")
|
|
for c in creds["results"]:
|
|
print(f" - [{c['id']}] {c['name']} (Type: {c['credential_type']})")
|
|
|
|
inventories = awx_get("inventories")
|
|
print(f"\nInventories ({inventories['count']}):")
|
|
for inv in inventories["results"]:
|
|
print(f" - [{inv['id']}] {inv['name']}")
|
|
|
|
projects = awx_get("projects")
|
|
print(f"\nProjects ({projects['count']}):")
|
|
for p in projects["results"]:
|
|
print(f" - [{p['id']}] {p['name']} (Status: {p['status']}, SCM: {p['scm_type']})")
|
|
|
|
templates = awx_get("job_templates")
|
|
print(f"\nJob Templates ({templates['count']}):")
|
|
for t in templates["results"]:
|
|
print(f" - [{t['id']}] {t['name']}")
|
|
|
|
except Exception as e:
|
|
print("AWX Query Error:", e)
|
|
|