Skip to content

Instantly share code, notes, and snippets.

@blackknight36
Created August 24, 2017 15:05
Show Gist options
  • Select an option

  • Save blackknight36/0db4407c5dcbe377988d7d78933a71dd to your computer and use it in GitHub Desktop.

Select an option

Save blackknight36/0db4407c5dcbe377988d7d78933a71dd to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import json
import platform
import requests
import os
#os.environ['PYTHONWARNINGS'] = 'ignore:Unverified HTTPS request'
hostname = platform.node()
url = 'https://puppetdb.example.com:8081/pdb/query/v4/nodes'
headers = {'Content-Type':'application/json'}
ssl_cert = '/etc/puppet/ssl/certs/%s.pem' %hostname
ssl_ca_cert = '/etc/puppet/ssl/ca/ca.pem'
ssl_key = '/etc/puppetl/ssl/private_keys/%s.pem' %hostname
query = '["=", ["fact", "operatingsystem"], "CentOS"]'
r = requests.post(url, headers=headers, json={"query": query}, verify=ssl_ca_cert, cert=(ssl_cert, ssl_key))
print json.dumps(json.loads(r.text), indent=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment