Skip to content

Instantly share code, notes, and snippets.

View charlesjohnson's full-sized avatar

Charles 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 / 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"
@charlesjohnson
charlesjohnson / default_attributes.rb
Created October 24, 2012 03:09
Ark library usage example
default['elasticsearch']['version'] = "0.19.6"
default['elasticsearch']['checksum'] = 'f0ec550fb86c4bc8f08afb15de4e197e85f9fcfd352fbb7eb49aaff98f7731dd'
default['elasticsearch']['url'] = "http://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-#{node['elasticsearch']['version']}.tar.gz"
default['elasticsearch']['home_path'] = "/usr/lib"
default['elasticsearch']['home_dir'] = "#{node['elasticsearch']['home_path']}/elasticsearch"