Skip to content

Instantly share code, notes, and snippets.

View randomcamel's full-sized avatar

Chris Doherty randomcamel

View GitHub Profile

Chef is a mighty set of tools that can automate and verify your infrastructure, but its full power is a lot to digest. Most of us learn new tools by trying them out for an hour or two, and that's usually how we make a decision. Today I want to show how you can get real value out of Chef real fast, maybe on a Friday afternoon with a couple of hours set aside for experimenting, by replacing a shell script with a list of Chef declarations. Then we can run that list using chef-apply, which executes a Chef runlist in a single file.

A Brief Note

Before we get started, it's worth mentioning that even though I'm going to pretend Chef is a scripting language, a Chef runlist describes the desired final state of a system, rather than providing a list of actions to execute. In other words, each Chef resource triggers code like this:

if system state already matches what the resource describes
then
 don't do anything
#!/usr/bin/env ruby
require 'json'
require 'logger'
log = Logger.new(STDOUT)
TEST_MODE = ARGV[0] == "--test"
fields = %w{ current_humidity current_temp_f aqi pressure }
@randomcamel
randomcamel / march.sh
Created April 15, 2022 16:58
A shell function to wrap a Perl invocation to tell you what day of March 2020 it is.
# I didn't write this, but it's too good not to share.
# See also: https://www.mcsweeneys.net/articles/heres-how-time-works-now.
march () {
perl -e 'use Date::Parse; use POSIX; my @t = localtime; print strftime ("%a Mar ", @t) . int (1 + 0.5 + ((str2time (strftime ("%Y-%m-%d 3:00", @t)) - str2time ("2020-03-01 3:00")) /(60*60*24))) . strftime (" %X %Z 2020\n", @t);'
}
docker-sh () {
dockershell=${2:-bash}
cmd="docker exec -it $1 /bin/$dockershell"
echo "running '$cmd' (-i -> interactive, -t -> allocate a tty)"
eval $cmd
}

Keybase proof

I hereby claim:

  • I am randomcamel on github.
  • I am cdoherty (https://keybase.io/cdoherty) on keybase.
  • I have a public key ASAFza9EFloxNSHqh-7qr53alNEQhr8gDAdEakMs6ELSDwo

To claim this, I am signing this object:

@randomcamel
randomcamel / brew-alias.sh
Last active June 16, 2021 20:54
Homebrew went through an irritating phase where you had to use `brew search` instead of `brew cask search`, even though you still had to do `brew cask install`.
brew () {
if [[ "x$1" == "xcask" && "x$2" == "xsearch" ]]; then
echo '`brew cask search` is broken, translating for you...'
shift
/usr/local/bin/brew $*
else
/usr/local/bin/brew $*
fi
}
#!/bin/sh
# uses rsync's hard-link feature to mimic the function and structure of Apple's Time Machine.
# my server's name is 'shiny', which I evidently used to mount on /backup.
TARGET=/backup/shiny
date=`date "+%Y-%m-%dT%H:%M:%S"`
rsync --exclude=.AppleDouble -aCPv --link-dest=$TARGET/current $HOME $TARGET/back-$date
cd $TARGET
@randomcamel
randomcamel / estimating.md
Last active March 1, 2022 23:26
Chris's Software Estimation
  1. know how much roadmap-project work people can do in a week. commonly it's 40-60% of their time. call that PR (for Project Ratio).

  2. make a spreadsheet: [Story, Description, People, Weeks, Person-Weeks].

  3. break the work down into comprehensible pieces, where you feel confident saying things like "this will take 2 people, working full-time, 3 weeks to implement." in particular, break down milestones that deliver value; where, if the business told you to do something else, that would be okay, and the work done wasn't wasted.

  4. fill in your spreadsheet columns appropriately (say 2 people, 3 weeks, 6 Person-Weeks).

  5. sum up the Person-Weeks. ("People" and "Weeks" are for later.)

This is a bit of history and a bit of a quirk in timing...

The history first...

Vagrant has all manner of provisioners effectively supporting any CM tool as well as supporting plugins to add more. When I started on Packer, I basically copied this model (nit: provisioners aren't pluggable anymore cause no one ever used that functionality but the interfaces are very similar and Packer also supports all manner of CM tool).

# Install prereqs with Homebrew:
#
# uninstall moreutils if installed:
# `brew uninstall moreutils`
#
# brew install wget
# brew install poppler
# brew install parallel
# brew install moreutils --without-parallel
set -e