Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jbergstroem/6e5e8a5e1668986f92202a657baf6335 to your computer and use it in GitHub Desktop.

Select an option

Save jbergstroem/6e5e8a5e1668986f92202a657baf6335 to your computer and use it in GitHub Desktop.
try:
from ansible.inventory.ini import InventoryParser
except ImportError:
try:
# homebrew likes to mess around with PYTHONPATH
# just try to parse out the homebrew stuff and fail miserably otherwise
results = [re.match(r'PYTHONPATH="(.*?)"', line)
# needs to open ansible from $path
for line in open('/usr/local/bin/ansible')]
# Remove lines that contains no matches
match = [_f for _f in results if _f]
# Append paths to PYTHONPATH
[sys.path.append(m) for m in match[0].group(1).split(":")]
from ansible.inventory.ini import InventoryParser
except:
print("Sorry, couldn't find Ansible.")
sys.exit(1)
from ansible.parsing.dataloader import DataLoader
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment