Skip to content

Instantly share code, notes, and snippets.

@mika
Last active August 29, 2015 14:14
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 mika/8fd61912cfd173d9f5a8 to your computer and use it in GitHub Desktop.
Save mika/8fd61912cfd173d9f5a8 to your computer and use it in GitHub Desktop.
puppetdb<->ansible
[int]
inta1-web01.in...
inta1-nfs01.in...
inta1-db02.in...
[prod]
proda1-api02.in...
proda1-scripts01.in...
#!/usr/bin/env python
import json
import requests
GROUP_FACT = 'devenv'
data = requests.get('http://localhost:8080/v3/facts/' + GROUP_FACT).json()
groups = {}
for hostdata in data:
groupname = hostdata['value']
if groupname not in groups:
groups[groupname] = []
groups[groupname].append(hostdata['certname'])
for key, hosts in groups.items():
print "[%s]" % key
for host in hosts:
print "%s" % host
print ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment