Skip to content

Instantly share code, notes, and snippets.

@benagricola
Created February 26, 2015 19:15
Show Gist options
  • Save benagricola/fbe433a85b2b4a1d31f3 to your computer and use it in GitHub Desktop.
Save benagricola/fbe433a85b2b4a1d31f3 to your computer and use it in GitHub Desktop.
Convert PuppetDB output to Rundeck JSON format
#!/bin/bash
APIENDPOINT=${1:-"https://puppetdb:8081/v4"}
APICERT=${2:-"/etc/pki/tls/certs/localhost.crt"}
APIKEY=${3:-"/etc/pki/tls/private/localhost.key"}
APICA=${4:-"/etc/pki/tls/certs/ca.pem"}
RESOURCEFILE=${5}
CURLCMD="curl -s -X GET --cacert $APICA --key $APIKEY --cert $APICERT $APIENDPOINT"
JSON=$($CURLCMD/facts/ | jq -r -s '(reduce .[][] as $item({} ; .[$item.certname].attributes = .[$item.certname].attributes + {($item.name): $item.value} | .[$item.certname].attributes.hostname = .[$item.certname].attributes.fqdn | .[$item.certname].attributes.username = "root")) | {nodes: .}')
if [ -z "$RESOURCEFILE" ]; then
echo $JSON;
else
echo $JSON > $RESOURCEFILE;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment