Skip to content

Instantly share code, notes, and snippets.

###
# Use knife to put the apache2 0.9.1 cookbook in your local repository
##
[adam@latte](1)% ./knife cookbook site vendor apache2 0.9.1 ~/src/sandbox/opscode/chef/chef/bin
INFO: Downloading apache2 from the cookbooks site at version 0.9.1
INFO: Cookbook saved: /Users/adam/src/sandbox/opscode/chef-repo/cookbooks/apache2.tar.gz
INFO: Checking out the master branch.
INFO: Checking the status of the vendor branch.
INFO: Creating vendor branch.
INFO: Removing pre-existing version.
#
# Author:: Bryan McLellan ([email protected])
# Copyright:: Copyright (c) 2009 Bryan McLellan
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# cookbook/baz/files/default/bar exists
# cookbook/a/recipe/default.rb
remote_file "/tmp/bar" do
source "bar"
cookbook "baz"
end
# ^ Works in 0.8+
#
# cookbooks/ssh_authorized_key/resources/default.rb
#
def initialize(name, collection=nil, node=nil)
super(name, collection, node)
@action = :create
end
actions :create, :delete
# Check this out, rvm use rbx
ruby_block "rvm use rbx" do
block do
Chef::Mixin::Command.popen4('bash -l -c "rvm use 1.9.1 && env"') do |p,i,o,e|
o.each_line do |line|
env_bits = line.split("=")
ENV[env_bits[0]] = env_bits[1]
end
end
# Check this out, rvm use rbx
ruby_block "rvm use rbx" do
block do
Chef::Mixin::Command.popen4('bash -l -c "rvm use rbx && env"') do |p,i,o,e|
o.each_line do |line|
env_bits = line.split("=")
ENV[env_bits[0]] = env_bits[1]
end
end
#!/usr/bin/ruby
require 'chef'
require 'chef/config'
require 'chef/node'
Chef::Config.from_file("/home/stuff/.chef/knife.rb")
# Load and save a node
node = Chef::Node.load('somenode')
# Node has roles baz and bar
remote_file 'foo' do
source find_by(node.roles, "foo.erb")
end
# Translates to
# /cookbook/foo/files/default/baz/foo.erb
# /cookbook/foo/files/default/bar/foo.erb
#
# Normal specificity applies, per platform or node
# cookbooks/thefader_wp/libraries/deploy_wp.rb
class Chef
class Provider
class Deploy
class Revision
class Wordpress < Chef::Provider::Deploy::Revision
def enforce_ownership
end
end
# role
name 'base-packages'
default_attributes :packages => {
'build-essential' => "latest",
'gcc' => "3.0"
}
run_list "recipe[install-packages]"
# cookbooks/install-packages/recipe/default.rb