Skip to content

Instantly share code, notes, and snippets.

@matburt
Created September 15, 2017 18:53
Show Gist options
  • Select an option

  • Save matburt/22bde1d0550fe274799f113d51e8c712 to your computer and use it in GitHub Desktop.

Select an option

Save matburt/22bde1d0550fe274799f113d51e8c712 to your computer and use it in GitHub Desktop.
Large AWX Test Inventory Script
#!/usr/bin/env python
import json
import random
import string
ADDRESSES = ["ahost{}".format(e) for e in range(10000)]
GROUPS = ["agroup{}".format(e) for e in range(500)]
def main():
print(json.dumps(inventory(), sort_keys=True, indent=2))
def generate_vars(nvars, nbytes):
allvars = dict()
for n in range(nvars):
key = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(nbytes/2))
val = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(nbytes/2))
allvars[key] = val
return allvars
def inventory():
inv = dict(_meta=dict(hostvars=dict()))
blocks = len(ADDRESSES) / len(GROUPS)
start = 0
for g in GROUPS:
gd = dict(hosts=ADDRESSES[start:start+blocks],
vars=generate_vars(30, 8000))
inv[g] = gd
start += blocks
for h in ADDRESSES:
inv['_meta']['hostvars'][h] = generate_vars(30, 8000)
return inv
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment