Skip to content

Instantly share code, notes, and snippets.

View charlesjohnson's full-sized avatar

Chip Johnson charlesjohnson

View GitHub Profile
ruby_block "Copy Chef config file if running in a Vagrant guest" do
block do
::FileUtils.cp "/tmp/vagrant-chef-1/client.rb", "#{node['chef-client']['conf_dir']}/client.rb"
end
if ::File.exist?("#{node['chef-client']['conf_dir']}/client.rb")
not_if { ::FileUtils.compare_file("/tmp/vagrant-chef-1/client.rb", "#{node['chef-client']['conf_dir']}/client.rb") }
end
only_if ::File.exist?("/tmp/vagrant-chef-1/client.rb")
end
@charlesjohnson
charlesjohnson / default_spec.rb
Last active August 29, 2015 14:11
Example Chefspec
#
# Cookbook Name:: Cookbook
# Spec:: default
#
require 'spec_helper'
describe 'cookbook::default' do
shared_examples_for :the_default_behavior do
@charlesjohnson
charlesjohnson / Switch.md
Created December 16, 2014 20:52
Talk about insight

The leaders at IDEO, the world’s preeminent product design firm, have designed products and experiences ranging from the first Apple mouse to a new Red Cross blood donation procedure. They understand the need to prepare their employees — and, more important, their clients — for failure.

Tim Brown, the CEO of IDEO, says that every design process goes through “foggy periods.” One of IDEO’s designers even sketched out a “project mood chart” that predicts how people will feel at different phases of a project. It’s a U-shaped curve with a peak of positive emotion, labeled “hope,” at the beginning, and a second peak of positive emotion, labeled “confidence,” at the end. In between the two peaks is a negative emotional valley labeled “insight.” Brown says that design is “rarely a graceful leap from height to height.” When a team embarks on a new project, team members are filled with hope and optimism. As they start to collect data and observe real people struggling with existing products, they find that new ideas s

@charlesjohnson
charlesjohnson / foo.chef.rb
Last active November 4, 2019 05:47
Get bash / execute output from Chef
#!/opt/chefdk/bin/chef-apply
# Lifted pretty much verbatim from http://stackoverflow.com/questions/17813592/how-can-i-display-the-output-of-a-opscode-chef-bash-command-in-my-console)
results = "/tmp/output.txt"
file results do
action :delete
end
cmd = "ls /"
bash cmd do
@charlesjohnson
charlesjohnson / what_a_jerk.rb
Created February 22, 2015 00:10
A dirty gem trick, install dependency gems without prompting the user if that's what they actually want.
begin
gem 'chef-api'
rescue LoadError
require 'rubygems/dependency_installer'
Gem::DependencyInstaller.new(Gem::DependencyInstaller::DEFAULT_OPTIONS).install('chef-api')
end
require 'chef-api'
@charlesjohnson
charlesjohnson / break.rb
Last active August 29, 2015 14:23
chef-client 12.3 logging behavior
#temp/break.rb
directory '/test/foo' do
action :create
end
@charlesjohnson
charlesjohnson / break.rb
Created June 26, 2015 00:23
chef-client 12.4 logging behavior
#temp/break.rb
directory '/test/foo' do
action :create
end
@charlesjohnson
charlesjohnson / break.rb
Last active August 29, 2015 14:23
chef-client 11.18.2 logging behavior
#temp/break.rb
directory '/test/foo' do
action :create
end
Its a cookbook class that we use to abstract cookbooks and their
dependencies. The key method to look at is dependency_hash which creates
a hash based on the dependencies of the cookbook.
We do not explicitly do a reverse dependency lookup but we can use this
hash to infer a change in dependencies from a change in any cookbook in
an environment. So the flow is:
1. I change cookbook A and it gets sent to the chef server and indexed
@charlesjohnson
charlesjohnson / Policyfile
Created July 13, 2015 17:36
Coincidence?
#Policyfile for Jenkins
name "jenkins"
# Run_list
run_list "apt", "java", "jenkins::master", "recipe[policyfile_demo]"
# Attributes
default["greeting"] = "Attributes, f*** yeah"
override["attr_only_updating"] = "use -a"