Skip to content

Instantly share code, notes, and snippets.

PS C:\ruby> chef-apply package.rb
Recipe: (chef-apply cookbook)::(chef-apply recipe)
* log[lolwut ruby] action write (skipped due to only_if)
PS C:\ruby> vim .\package.rb
PS C:\ruby> chef-apply package.rb
Recipe: (chef-apply cookbook)::(chef-apply recipe)
* log[lolwut ruby] action write
PS C:\ruby> chef-apply package.rb -l info
[2014-06-26T13:16:07-04:00] INFO: Run List is []
[2014-06-26T13:16:07-04:00] INFO: Run List expands to []
Ohai.plugin(:Mdadm) do
provides 'mdadm'
def create_raid_device_mash(stdout)
device_mash = Mash.new
device_mash[:device_counts] = Mash.new
stdout.each do |line|
case line
when /Version\s+: ([0-9.]+)/
device_mash[:version] = Regexp.last_match[1].to_f
@btm
btm / gist:9532345
Last active August 29, 2015 13:57
Cookbook Namspacing
I wrote this on 2010-10-01, and I've been passing it around as the entry to my opinion on why we need namespacing on the community site. Maybe it's a terrible argument since we haven't implemented it yet, but it's a lot of words that I can save myself from typing over again.
I thought there were tickets or mailing list posts with opposition to namespacing, but I can't find them. Drop them in the comments if you know of any please.
Bryan McLellan <btm@loftninjas.org>
###
Earlier in the week we had a meeting (you guys rock) at HQ about
cookbook workflow and one of the subjects we discussed heavily was
cookbook namespace on the cookbook site. At the end of the meeting I
# Using Color in log messages in Chef
require 'highline'
# Use the log resource (runs during convergence)
log HighLine.new.color("foobar", :yellow)
# Use Chef::Log (runs during compilation)
Chef::Log.info(HighLine.new.color("foobar", :yellow))
@btm
btm / check_installed.rb
Last active January 4, 2016 20:19
utilities for getting microsoft installer product code data from ruby
# Reads a product code from an MSI file
# Checks if that product code is installed on the system
require 'rubygems'
require 'ffi'
require 'pathname'
PRODUCT_CODE_LENGTH = 38
module Win32
@btm
btm / README.md
Last active December 31, 2015 02:39
Could a well timed network failure turn curl | bash into a destructive accident?

There is an assertation that one reason the "curl | sudo bash" pattern is bad is because you may experience network failure and execute a partially downloaded script.

This:

rm -rf /tmp/random_directory

Could accidentally become:

rm -rf /
@btm
btm / install.sh.erb
Last active December 25, 2015 14:59
opscode-omnitruck/views/install.sh.erb 2013-10-15 / af7c7b45f0b60e0faef6c7b51108abae713e0c41
#!/bin/bash
# This is the current stable release to default to, with Omnibus patch level (e.g. 10.12.0-1)
# Note that the chef template downloads 'x.y.z' not 'x.y.z-r' which should be a duplicate of the latest -r
use_shell=0
prerelease="false"
# Check whether a command exists - returns 0 if it does, 1 if it does not
exists() {
@btm
btm / cvar.rb
Created September 30, 2013 17:59
redefining a class that sets a class variable will recreate the class variable
class A
@@cvar = {}
def mutate
@@cvar[:foo] = "bar"
end
def add(k,v)
@@cvar[k] = v
end
@btm
btm / gist:6700524
Last active February 26, 2024 01:10
Why curl | sudo bash is good: it is simple single line, and uses the same channel that downloading a repository signing key would.

Easy one line Chef installation for all platforms (except windows)

curl https://www.opscode.com/chef/install.sh | sudo bash

That's it. This can be put in any instructions, such as a README or someone's blog, since the logic is in the shell script. Provided you download the script using https, the file has standard levels of authentication and encryption protecting it from manipulation.

This is obviously a shell script, if you're really concerned about the argument that it may contain nefarious activities within, you can easily review it before you run it.

@btm
btm / gist:6233398
Created August 14, 2013 17:35
Using grep against STDERR
# This error goes to STDERR
$ asdfasdf
-bash: asdfasdf: command not found
# We redirect STDERR to STDOUT, but STDOUT to null, so we can use grep against STDERR
$ asdfasdf 2>&1 >/dev/null | grep -q not ; echo $?
0