Created
September 15, 2017 18:53
-
-
Save matburt/22bde1d0550fe274799f113d51e8c712 to your computer and use it in GitHub Desktop.
Large AWX Test Inventory Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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