Skip to content

Instantly share code, notes, and snippets.

View smbambling's full-sized avatar

Steven Bambling smbambling

View GitHub Profile
@smbambling
smbambling / gist:a4b26986d46cd7bac1e5
Created March 27, 2015 11:08
Sort files by human readable size
du -sk * | sort -rn | awk '{print $2}' | xargs -ia du -hs "a"
@smbambling
smbambling / exists.rb
Last active August 29, 2015 14:25 — forked from j4m3s/exists.rb
#
# exists.rb
#
# James Fellows 8/8/12: cloned from git://gist.github.com/1160472.git then
# modified to resolve puppet:/// paths
#
# Copyright 2011 Puppet Labs Inc.
# Copyright 2011 Krzysztof Wilczynski
#
# Licensed under the Apache License, Version 2.0 (the "License");
@smbambling
smbambling / fetch_resource_types.rb
Last active November 2, 2015 18:08
Puppet Function to return list (array) of resource types (classes) from the Puppet API from a supplied regex
require "net/http"
require "net/https"
require "uri"
require "json"
require "socket"
require "puppet"
module Puppet::Parser::Functions
newfunction(:fetch_resource_types, :type => :rvalue) do |args|
require "net/http"
require "net/https"
require "uri"
require "json"
require "socket"
require "puppet"
module Puppet::Parser::Functions
newfunction(:fetch_environments, :type => :rvalue) do |args|
@smbambling
smbambling / puppetserver_irb.rb
Last active November 5, 2015 12:36
Snippet used with puppetserver irb to get info
require 'irb/completion'
require 'puppet'
Puppet.settings.preferred_run_mode = :agent # or whatever section you need
Puppet.settings.initialize_global_settings(["--config=/the/config/file"])
Puppet.settings.initialize_app_defaults(
Puppet::Settings.app_defaults_for_run_mode(Puppet.run_mode)
)
Puppet.push_context(Puppet.base_context(Puppet.settings))
@smbambling
smbambling / pe_classifier_group.pp
Last active November 11, 2015 14:11
Puppet Class to auto create PE Classifier Environment groups based on PuppetServer environments
## This class requires env_utils, node_manager and stdlib
# Array of PE Environment Groups excluding the default 'Agent-specified environment' group
$pe_environment_groups = delete(node_groups().filter |$key, $val| { $val["environment_trumps"] == true }.map |$key, $val| { $val["name"] }, 'Agent-specified environment')
# Obtain PuppetServer environments and munge to look like PE Classifier environment Groups
$puppet_environments = regsubst(capitalize(environments()), '$', ' environment', 'G')
# Array of PE Environment Groups that should be removed based
# the PuppetServer environment no longer exists
$managed_groups = hiera_array(managed_groups)
notice ( $managed_groups )
$managed_groups.each | $group | {
$g = hiera_hash(accounts::groups).filter | $key, $val | { $key == $group }
create_resources('group', $g)
}
$managed_users = hiera_array(managed_users)
@smbambling
smbambling / .vimrc
Created November 24, 2015 19:33
Bambling .vimrc
" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible " be iMproved, required
filetype off " required
" ================ General Config ====================
set number "Line numbers are good
set backspace=indent,eol,start "Allow backspace in insert mode
set history=1000 "Store lots of :cmdline history
@smbambling
smbambling / available_ips.sh
Created February 5, 2016 13:59
Find available IP addresses using DNS and DIG ( -x axfr )
#!/usr/bin/env bash
# Find available IP addresses from by using dig -x axfr
usage() {
cat <<-EOF
usage: ${0} <network>
example: ${0} 10.1.10
EOF
}
@smbambling
smbambling / cmd_exists.sh
Created February 11, 2016 13:43
Check if a command called in a script exists.
# Reference Commands
cmd_list='usermod groupmod find chgrp getent id awk tr wc'
# Function to check if referenced command exists
cmd_exists() {
if [ $# -eq 0 ]; then
echo 'WARNING: No command argument was passed to verify exists'
fi
cmd=${1}