Created
May 18, 2017 07:34
-
-
Save Voronenko/59f389b6cccc8afc2bc7b3466b05af92 to your computer and use it in GitHub Desktop.
ansible /etc/hosts inventory
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 | |
hosts = open('/etc/hosts','r') | |
result={} | |
allservers=[] | |
for line in hosts: | |
if line[0].isdigit(): | |
host = line.split() | |
result[host[1]]= {} | |
result[host[1]]["hosts"] = [host[0]] | |
allservers.append(host[1]) | |
result["allhosts"] = {} | |
result["allhosts"]["children"]=allservers | |
print json.dumps(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment