Skip to content

Instantly share code, notes, and snippets.

@jtyr
Last active April 25, 2019 10:35
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save jtyr/5213fabf2bcb943efc82f00959b91163 to your computer and use it in GitHub Desktop.
Save jtyr/5213fabf2bcb943efc82f00959b91163 to your computer and use it in GitHub Desktop.
Ansible dynamic inventory script that reads any Ansible hosts file and transforms it into the JSON data structure.
This was moved to https://github.com/jtyr/ansible-ini_inventory
@mterzo
Copy link

mterzo commented Jan 18, 2018

Found this tip really useful. Thanks for putting this together. got me looking for what I needed in the 2.4 patch

Here's something similar to what I've implemented in my code.

from ansible.plugins.inventory import expand_hostname_range, detect_range

def my_expand(host_line):
  hosts = []
  if detect_range(host_line):
    hosts += expand_hostname_range(host_line)
  else:
    hosts += [host_line]
  return hosts

@narkq
Copy link

narkq commented Mar 27, 2018

@jtyr
Copy link
Author

jtyr commented Jul 12, 2018

I have fixed to error and moved the script into a proper GitHub repo here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment