Skip to content

Instantly share code, notes, and snippets.

@treydock
Created October 16, 2014 04:35
Show Gist options
  • Select an option

  • Save treydock/2bf5e08caf4284c19c14 to your computer and use it in GitHub Desktop.

Select an option

Save treydock/2bf5e08caf4284c19c14 to your computer and use it in GitHub Desktop.
Puppet masterless script
#!/bin/bash
readonly ENVIRONMENTPATH="/apps/puppet/environments"
readonly DEF_ENV="production"
readonly PROGNAME=$(basename $0)
usage () {
cat << EOF
usage: ${PROGNAME} [OPTIONS]
Puppet masterless script.
All arguments are passed to "puppet apply" except those listed under OPTIONS.
OPTIONS:
-d, --debug Show debug output
-h, --help Show this message
EXAMPLES:
Run puppet apply against site.pp in ${ENVIRONMENTPATH}/${DEF_ENV}/manifests
${PROGNAME}
Run puppet apply using --noop against site.pp in ${ENVIRONMENTPATH}/${DEF_ENV}/manifests
${PROGNAME} --noop
EOF
}
ARGS=()
while test ${#} -gt 0; do
case $1 in
-h|--help) usage ; exit 0 ;;
-d|--debug) set -x ;;
*) ARGS+=($1) ;;
esac
shift
done
ENVIRONMENT="${PUPPET_ENV:-$DEF_ENV}"
PUPPET_ARGS="${ARGS[@]}"
CONFDIR="${ENVIRONMENTPATH}/${ENVIRONMENT}"
SITEPP="${CONFDIR}/manifests/site.pp"
CMD="puppet apply --confdir ${CONFDIR} ${SITEPP} --write-catalog-summary ${PUPPET_ARGS}"
if [ ! -f /var/lib/puppet/state/agent_disabled.lock ]; then
eval $CMD
ret=$?
fi
exit $ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment