Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save smbambling/ca3fc0cee2ba2b96c827ca746362b537 to your computer and use it in GitHub Desktop.
Save smbambling/ca3fc0cee2ba2b96c827ca746362b537 to your computer and use it in GitHub Desktop.
Puppet Command Aliases
######################################################################
######################################################################
# Managed by Puppet
#
# NOTE: Changes made to this file will be
# overwritten during the next update, default: 30 min
######################################################################
######################################################################
# Bash only checks the first word of a command for an alias,
# any words after that are not checked. We can tell bash to check
# the next word after the alias (i.e sudo) by adding a space to the end of the alias value.
alias sudo='sudo '
# Set BASH History Timestamp
export HISTTIMEFORMAT="%d/%m/%y %T "
# Puppet Enterprise Aliases
puppet_bindir='/opt/puppetlabs/bin'
# Puppet agent run alias
alias pup_agent="sudo ${puppet_bindir}/puppet agent -t"
# Puppet apply run alias
if type -f ${puppet_bindir}/facter &>/dev/null; then # portable 'which'
if [ "$(${puppet_bindir}/facter virtual)" == 'virtualbox' ]; then
pup_apply() {
sudo ${puppet_bindir}/puppet apply \
--hiera_config=/vagrant/puppet/environments/dev/hiera.yaml \
--modulepath="/vagrant/puppet/environments/dev/site:/vagrant/puppet/environments/dev/modules/" \
/vagrant/puppet/environments/dev/manifests/site.pp;
}
fi
fi
# Puppet environment set alias
alias pup_setenv="sudo ${puppet_bindir}/puppet config set --section agent environment"
# List files in the current local filebucket
# Output: <md5sum> <date> <time> <file_path>
# Options:
# --files: list only unquie filenames from the local filebucket
# <search string>: list <md5sum> <date> <time> <file_path> for search string
# <nothing supplied>: list <md5sum> <date> <time> <file_path> for all files
#
# Ex: pup_fb_list --files
# pup_fb_list <file_path>
# pup_fb_list
pup_fb_list() {
puppet_bindir='/opt/puppetlabs/bin'
local_clientbucket='/opt/puppetlabs/puppet/cache/clientbucket'
filebucket_cmd="${puppet_bindir}/puppet filebucket -l --bucketdir=${local_clientbucket}"
if [ -z "${1}" ]; then
sudo $filebucket_cmd list
elif [ "${1}" == '--files' ]; then
sudo $filebucket_cmd list |\
awk '!x[$4]++ { print $4}'
elif [ ! -z "$file_name" ]; then
sudo $filebucket_cmd list |\
awk -v patt="${1}" '$0 ~ patt { print $0 }'
fi
}
# Print diff contents of the latest backed up version in the local filebucket
# with the provided <file_path>
# Ex: pup_fb_diff_latest <file_path>
pup_fb_diff_latest() {
if [[ "$SHELL" == "*zsh*" ]]; then
emulate -L ksh
fi
puppet_bindir='/opt/puppetlabs/bin'
local_clientbucket='/opt/puppetlabs/puppet/cache/clientbucket'
filebucket_cmd="${puppet_bindir}/puppet filebucket -l --bucketdir=${local_clientbucket}"
fb_output=($(sudo ${filebucket_cmd} list |\
awk -v patt="${1}" '$0 ~ patt {a=$0} END{ print a }'))
file_md5sum=${fb_output[0]}
file_path=${fb_output[3]}
sudo ${filebucket_cmd} diff ${file_md5sum} ${file_path}
}
# Print the content output of a provided md5sum from the local filebucket
# Ex: pup_fb_get <md5sum>
pup_fb_get() {
puppet_bindir='/opt/puppetlabs/bin'
local_clientbucket='/opt/puppetlabs/puppet/cache/clientbucket'
filebucket_cmd="${puppet_bindir}/puppet filebucket -l --bucketdir=${local_clientbucket}"
sudo ${filebucket_cmd} get ${1}
}
# Restore the contents from a provided md5sum from the local filebucket
# to a provided file system location
# Ex: pup_fb_restore <file_path> <md5sum>
pup_fb_restore() {
puppet_bindir='/opt/puppetlabs/bin'
local_clientbucket='/opt/puppetlabs/puppet/cache/clientbucket'
filebucket_cmd="${puppet_bindir}/puppet filebucket -l --bucketdir=${local_clientbucket}"
sudo ${filebucket_cmd} restore ${1} ${2}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment