KB: Ansible AWX Inventory script

Ansible AWX Inventory:
Setting up AWX inventory script:

Python Script to read the HTTP REST API

#!/usr/bin/env python3

# -*- coding: utf-8 -*-
import os
import re
import urllib
import argparse
import ssl
import sys


#Python 3.0 and later
from urllib.request import urlopen
import json

parser = argparse.ArgumentParser(
    description='Script to obtain host inventory from AD')
    parser.add_argument('--list', action='store_true',
    help='prints a json of hosts with groups and variables')
parser.add_argument('--host', help='returns variables of given host')
args = parser.parse_args()

if __name__ == '__main__':
    data = urllib.request.urlopen("http://nodesvcserver/ansible/GetWorkstations?$adgroupmemberlist=QA_Workstations&$flushcache=true").read()
    output = json.loads(data)
    print(json.dumps(output))


How payload/model looks like:




Reference:
https://developers.redhat.com/blog/2021/03/10/write-your-own-red-hat-ansible-tower-inventory-plugin

Comments

Popular posts from this blog

KB: Azure ACA Container fails to start (no User Assigned or Delegated Managed Identity found for specified ClientId)

Electron Process Execution Failure with FSLogix

KB:RMM VS DEX (Remote Monitoring Management vs Digital Employee Experience)