Skip to content

Instantly share code, notes, and snippets.

@TJM
Created October 17, 2018 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TJM/af9c0f0e6d7a1ebcb32be961d41e24b7 to your computer and use it in GitHub Desktop.
Save TJM/af9c0f0e6d7a1ebcb32be961d41e24b7 to your computer and use it in GitHub Desktop.
Puppet Catalog script
#!/bin/bash
#
# catalog
# John Simpson <jms1@jms1.net> 2015-10-30
#
# Prints a Puppet node's catalog file.
# This *should* work with both OSP and PE.
#
# 2017-10-11 jms1 - adding "run" option
########################################
# Find the client_datadir
DATADIR=$( puppet config print client_datadir )
if [[ -z "$DATADIR" ]]
then
echo "ERROR: 'puppet config print client_datadir' did not return a directory"
exit 1
fi
if [[ ! -d "$DATADIR/catalog" ]]
then
echo "ERROR: '$DATADIR/catalog' directory does not exist"
exit 1
fi
########################################
# Make sure the catalog file exists
CATALOG="$DATADIR/catalog/$( hostname -f ).json"
if [[ ! -f "$CATALOG" ]]
then
echo "ERROR: '$CATALOG' file does not exist"
exit 1
fi
########################################
# If we're not being told to run the catalog, print it
if [[ "${1:-}" != "run" ]]
then
exec cat "$CATALOG"
fi
########################################
# We've been told to run the catalog. This requires root privileges.
if [[ "$( id -u )" != "0" ]]
then
echo "ERROR: you must be root to apply a catalog"
exit 1
fi
exec puppet apply --catalog "$CATALOG"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment