Skip to content

Instantly share code, notes, and snippets.

@GeoffWilliams
GeoffWilliams / Rakefile
Created December 10, 2018 23:59
recursive yaml file validation, run by executing `rake`
# Check YAML files for syntax
task :default do
require 'yaml'
d = Dir["./**/*.yaml"]
d.each do |file|
begin
f = YAML.load_file(file)
rescue Exception
puts "Invalid YAML #{file}: #{$!}"
end
@GeoffWilliams
GeoffWilliams / catalog_params.py
Created December 10, 2018 02:59
Dump the class parameters given to a class in puppet
import json
import pprint
import subprocess
clientcert = subprocess.check_output(['puppet', 'config', 'print', 'certname']).strip()
catalog_file = '/opt/puppetlabs/puppet/cache/client_data/catalog/' + clientcert + '.json'
with open(catalog_file) as f:
data = json.load(f)
pp = pprint.PrettyPrinter(indent=4)
for res in data['resources']:
This file has been truncated, but you can view the full file.
Rule Name: Microsoft Whiteboard
----------------------------------------------------------------------
Description: Microsoft Whiteboard
Enabled: Yes
Direction: Out
Profiles: Domain,Private,Public
Grouping: Microsoft Whiteboard
LocalIP: Any
RemoteIP: Any
@GeoffWilliams
GeoffWilliams / packer.log
Created October 26, 2018 09:11
packer debug output - vmware 15
geoff@computer:~/github/boxcutter_windows$ make eval-win10x64-enterprise --debu
GNU Make 4.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Updating goal targets....
File 'eval-win10x64-enterprise' does not exist.
@GeoffWilliams
GeoffWilliams / fun_with_functions.pp
Created October 3, 2018 14:51
Example of how to use Puppet, iteration and functions to figure out what to look up from hiera, look it up and then collect the results in a file
# big parameters for testcase purposes - normally default to empty hash and lookup from hiera
class profiles::myapp(
Hash $packages = {
"vb" => {
description => "the best beer in australia",
},
"oldgnarlyhen" => {
description => "for hipsters",
}
},
@GeoffWilliams
GeoffWilliams / each_git_rev.sh
Created September 19, 2018 15:12
get all revisions from a file from git and copy to directory
REFS=$(git log Gemfile | grep commit | awk '{print $2}')
for REF in $REFS ; do
git checkout $REF Gemfile
mkdir -p gemfiles/$REF
cp Gemfile gemfiles/$REF
done
@GeoffWilliams
GeoffWilliams / jsonmap.go
Last active August 25, 2018 08:27
read/write json from a map to a file. Why use a struct over a map? ... if you need to mix datatypes (hmm... dont... - use interface{}) you have to
package main
import (
"encoding/json"
"io/ioutil"
"os"
"log"
)
var stderr = log.New(os.Stderr, "RUHROH-->", 0)
@GeoffWilliams
GeoffWilliams / main.go
Created August 24, 2018 23:47
read and write JSON to file using golang
package main
import (
"encoding/json"
"io/ioutil"
"os"
"log"
)
type Person struct {
@GeoffWilliams
GeoffWilliams / unzip.ps1
Created August 22, 2018 04:46
Unzip a file using powershell, overwriting any existing files
Add-Type -AssemblyName System.IO.Compression.FileSystem
$zipFile = [System.IO.Compression.ZipFile]::openread("c:\Vagrant\download_and_do\spec\mock\test.zip")
foreach ($zipFileEntry in $zipFile.Entries) {
$pwd = (Get-Item -Path ".\" -Verbose).FullName
$outputFile = [io.path]::combine($pwd, $zipFileEntry.FullName)
$dir = ([io.fileinfo]$outputFile).DirectoryName
if (-not(Test-Path -type Container -path $dir)) {
@GeoffWilliams
GeoffWilliams / configure_app.ps1
Created July 17, 2018 04:02
configure an application by looking up stuff from a .json file and writing XMLs from it
#<#
#.Synopsis
# Rewrite configuration files based on hiera data
#.Description
# ..
#
#.Parameter DataFile
# Exported data from hiera (JSON)
#.Parameter AppData
# File to read configurable settings from