Instantly share code, notes, and snippets.

@jtyr /hostsfile.py
Last active Jul 12, 2018

Embed
What would you like to do?
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
@andrew-sumner

This comment has been minimized.

Show comment
Hide comment
@andrew-sumner

andrew-sumner Dec 5, 2017

This doesn't work for me after upgrading to Ansible 2.4 as it's unable to find InventoryParser. Do you have a fix (or suggestion) for this?

andrew-sumner commented Dec 5, 2017

This doesn't work for me after upgrading to Ansible 2.4 as it's unable to find InventoryParser. Do you have a fix (or suggestion) for this?

@derekslenk

This comment has been minimized.

Show comment
Hide comment
@derekslenk

derekslenk Dec 28, 2017

I am having the same issue as @andrew-sumner...would love to know if anyone knows of a fix

edit
it looks like ansible 2.4 doesn't include an InventoryParser class anymore.

derekslenk commented Dec 28, 2017

I am having the same issue as @andrew-sumner...would love to know if anyone knows of a fix

edit
it looks like ansible 2.4 doesn't include an InventoryParser class anymore.

@mterzo

This comment has been minimized.

Show comment
Hide comment
@mterzo

mterzo 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

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

This comment has been minimized.

Show comment
Hide comment
@narkq

narkq commented Mar 27, 2018

@jtyr

This comment has been minimized.

Show comment
Hide comment
@jtyr

jtyr Jul 12, 2018

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

Owner

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