Created
February 26, 2015 19:15
-
-
Save benagricola/fbe433a85b2b4a1d31f3 to your computer and use it in GitHub Desktop.
Convert PuppetDB output to Rundeck JSON format
This file contains 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
#!/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