Skip to content

Instantly share code, notes, and snippets.

@palmerc
Created February 28, 2024 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save palmerc/3f0ad7f4229a8ca509951d98e43e8af9 to your computer and use it in GitHub Desktop.
Save palmerc/3f0ad7f4229a8ca509951d98e43e8af9 to your computer and use it in GitHub Desktop.
Convert Ansible Inventory yaml to Remote Desktop importable plist
import yaml
import plistlib
import uuid
def main():
hosts = None
with open('inventory.yml') as f:
for yml in yaml.safe_load_all(f):
hosts = yml['all']['children']['production']['hosts']
items = []
for host in hosts:
items.append({'hostname': host})
body = { 'items': items, 'listName': 'All Computers', 'uuid': str(uuid.uuid1()) }
plist = plistlib.dumps(body)
with open('all_computers.plist', 'wb') as f:
f.write(plist)
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment