Skip to content

Instantly share code, notes, and snippets.

@purplexa
Created August 17, 2016 20:02
Show Gist options
  • Save purplexa/e37f6953462f85050b7664a01ba976a0 to your computer and use it in GitHub Desktop.
Save purplexa/e37f6953462f85050b7664a01ba976a0 to your computer and use it in GitHub Desktop.
Bash function for hitting the PuppetDB API, for when you want to use PQL but don't have the cli tool installed
function pql {
tmpfile=$(mktemp)
status_code=$(curl --silent --output /dev/stderr --write-out "%{http_code}" -XGET localhost:8080/pdb/query/v4 -d "query=$1" 2>$tmpfile)
if [ "$status_code" = "200" ]; then
jq $3 "$2" $tmpfile
else
cat $tmpfile
fi
rm $tmpfile
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment