Skip to content

Instantly share code, notes, and snippets.

@natemccurdy
Last active August 18, 2023 15:50
Show Gist options
  • Save natemccurdy/65676368168708810c29 to your computer and use it in GitHub Desktop.
Save natemccurdy/65676368168708810c29 to your computer and use it in GitHub Desktop.
Get the list of environments known to a puppet master
#!/bin/bash
# GIST_URL: https://gist.github.com/natemccurdy/65676368168708810c29
# Get the list of classes that the Puppetserver knows about.
# https://docs.puppetlabs.com/puppet/latest/reference/http_api/http_environments.html
CERT="$(puppet agent --configprint hostcert)"
CACERT="$(puppet agent --configprint localcacert)"
PRVKEY="$(puppet agent --configprint hostprivkey)"
OPTIONS="--cert ${CERT} --cacert ${CACERT} --key ${PRVKEY}"
MASTER="$(puppet agent --configprint server)"
/opt/puppetlabs/puppet/bin/curl -s -X GET $OPTIONS "https://${MASTER}:8140/puppet/v3/environments" | python -m json.tool
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment