Skip to content

Instantly share code, notes, and snippets.

@GeoffWilliams
GeoffWilliams / docker.pp
Created March 8, 2016 00:56
Docker in PE example profile. Sets up Docker and runs mongo. Copy to /etc/puppetlabs/code/environments/production/site/profile/manifests/docker.pp -- then create role::docker and clasify NAMED node using site.pp. Dont do default as it may take over other sytems
class profile::docker {
include docker
$image = "mongo"
docker::image { $image: }
docker::run { $image:
image => $image,
}
}
@GeoffWilliams
GeoffWilliams / myfact.rb
Last active June 10, 2016 05:29
Example of how to do a custom fact parsing output from a perl script that outputs YAML. This ruby file must be distributed via a module as a custom fact and should be saved in the modules lib/facter directory. The facter command can then be used to inspect the resulting structure, eg facter -p myfact.testdata.data1
require 'yaml'
Facter.add(:myfact) do
setcode do
YAML.load(Facter::Core::Execution.exec("/usr/local/bin/mycoolscript.pl"))
end
end
@GeoffWilliams
GeoffWilliams / namegenerator.py
Last active July 23, 2016 12:28
Generate cool names for things that are hard to name from a wordlist. Entries in the wordlist should start with star and a space, one per line. Other notes will be ignored
#!/usr/bin/env python
import random
import re
import argparse
parser = argparse.ArgumentParser(description="Generate names from wordlist")
parser.add_argument('--wordlist', default='wordlist', help='wordlist file to read')
parser.add_argument('--iterations', default=100, type=int, help='how many words to generate?')
parser.add_argument('--words', default=3, type=int, help='how many words to fuse together')
parser.add_argument('--min', default=2, type=int, help='min letters to pick from word')
parser.add_argument('--max', default=4, type=int, help='max letters to pick from word')
@GeoffWilliams
GeoffWilliams / zendesk2html.py
Last active August 13, 2016 03:25
Convert copy and pasted plaintext zendesk support ticket data into a html table - you can then open it in excel and manipulate the data :) how to use: copy the body of the helpdesk ticket and paste into a plain text file called ticket.txt, then run this script and capture the output. Save as .xls to open in excel
#!/usr/bin/env python
import textwrap
def format_header(date, user):
output = "<tr><td>{date}</td><td>{user}</td><td><pre>".format(
date=date,
user=user,
)
return output
#!/bin/bash
#
# Ask systemctl to do something with puppet services
if [ -z "$1" ] ; then
echo "must be run with an argument for systemct"
exit 1
fi
systemctl $1 puppet
systemctl $1 mcollective
systemctl $1 pxp-agent
@GeoffWilliams
GeoffWilliams / link.sh
Created November 3, 2016 00:24
create symlinks for pe_kit to allow module development in /shared
@GeoffWilliams
GeoffWilliams / _etc_config_polipo
Created November 5, 2016 02:33
polipo config for openwrt
# polipo daemon configuration
# /etc/config/polipo
config 'polipo' 'daemon'
# daemonise polipo (fork in background)
option 'daemonise' '1'
# where polipo will store its process pid
option 'pidFile' '/var/run/polipo.pid'
config 'polipo' 'general'
option 'enabled' '1'
@GeoffWilliams
GeoffWilliams / delete_puppet_certs.bat
Last active November 9, 2016 23:23
Delete puppet SSL certs on windows
del /S/Q c:\ProgramData\PuppetLabs\puppet\etc\ssl
@GeoffWilliams
GeoffWilliams / puppet_ssl_test.sh
Created November 18, 2016 03:51
Quick way to test out puppet SSL connections that are giving crazy ssl errors, adapted from http://www.masterzen.fr/2010/11/14/puppet-ssl-explained/ to not need you to type any paths. Ctrl+f to send a request. Thanks to Ben Ford from Puppet.com for putting me on to this!
openssl s_client -host $(puppet config print server) -port 8140 -cert $(puppet config print certdir)/$(puppet config print certname).pem -key $(puppet config print privatekeydir)/$(puppet config print certname).pem -CAfile $(puppet config print certdir)/ca.pem
@GeoffWilliams
GeoffWilliams / rfc1918.rb
Created January 4, 2017 01:10
Module to detect whether an IP address is rfc1918 or not (private class A, B, C + loopback)
# From https://gist.github.com/bmc/2728451
module RFC1918
def self.is_unroutable(ip)
if ! (ip =~ /^(\d{1,3}).(\d{1,3}).(\d{1,3}).(\d{1,3})$/)
raise "#{ip} is not an IP address"
end
octets = [$1, $2, $3, $4].map &:to_i
raise "#{ip} is a bad IP address" unless octets.all? {|o| o < 256}