"edit" your resources in a library cookbook from an application cookbook

ahead of tomorrow’s G+ hangout on Cookbook reusability, I whipped up
this little gem that embodies what I have in mind for making cookbooks
more reusable. This is alpha level code.

chef-edit essentially allows you to reopen an existing resource. It is
mostly just syntactic sugar on top of the Chef::Recipe.resources
method

https://github.com/bryanwb/chef-edit

Add this line to your application’s Gemfile:

Installation

gem 'chef-edit’
And then execute:

$ bundle
Or install it yourself as:

$ gem install chef-edit

Usage

file postgresql/recipes/server.rb

user “postgres” do
uid 26
home '/home/postgres’
supports :manage_home => true
end

file my-postgresql/recipes/

require ‘chef/edit’

include_recipe “postgresql::server”

edit "user[postgres]"
home '/var/lib/pgsql/9.2’
end

Dear Chef users!

chef-edit has been renamed chef-rewind
GitHub - bryanwb/chef-rewind: monkeypatch chef to edit existing resources in place , enjoy!

file postgresql/recipes/server.rb

user "postgres" do
uid 26
home '/home/postgres'
supports :manage_home => true
end

file my-postgresql/recipes/

require 'chef/edit'

include_recipe "postgresql::server"

rewind "user[postgres]"
home '/var/lib/pgsql/9.2'
end

On Wed, Nov 7, 2012 at 6:51 PM, Bryan Berry bryan.berry@gmail.com wrote:

ahead of tomorrow's G+ hangout on Cookbook reusability, I whipped up
this little gem that embodies what I have in mind for making cookbooks
more reusable. This is alpha level code.

chef-edit essentially allows you to reopen an existing resource. It is
mostly just syntactic sugar on top of the Chef::Recipe.resources
method

https://github.com/bryanwb/chef-edit

Add this line to your application's Gemfile:

Installation

gem 'chef-edit'
And then execute:

Or install it yourself as:

$ gem install chef-edit

Usage

file postgresql/recipes/server.rb

user "postgres" do
uid 26
home '/home/postgres'
supports :manage_home => true
end

file my-postgresql/recipes/

require 'chef/edit'

include_recipe "postgresql::server"

edit "user[postgres]"
home '/var/lib/pgsql/9.2'
end

FWIW, I took this and simply dropped it into the libraries folder in a
chef cookbook.

Then easily used it to take the portertech redis cookbook and
monkeypatched the redis.conf template it in for 2.6.4

% cat sk_chef_rewind/libraries/rewind.rb
[…chef_rewind library…]

% cat sk_redis/metadata.rb
depends “sk_chef_rewind”

% cat sk_redis/recipes/default.rb
rewind “template[#{node[‘redis’][‘conf_dir’]}/redis.conf]” do
cookbook_name "sk_redis"
end

% cat sk_redis/templates/default/redis.conf.erb
[…redis.conf template hacked up to remove vm-* options and rename some
others…]

% cat roles/redis.rb
name "redis"
description "role for deploying redis"
override_attributes({
“redis” => {
“install_type” => “source”
}
})
run_list(
“recipe[portertech_redis::server]”,
“recipe[sk_redis]”
)

Hey Lamont,

I intent to send a pull request to include chef-rewind into chef itself. If
that PR is accepted, you won't have to add it to a cookbook at all

On Tue, Nov 13, 2012 at 5:53 AM, Lamont Granquist lamont@opscode.comwrote:

FWIW, I took this and simply dropped it into the libraries folder in a
chef cookbook.

Then easily used it to take the portertech redis cookbook and
monkeypatched the redis.conf template it in for 2.6.4

% cat sk_chef_rewind/libraries/**rewind.rb
[...chef_rewind library...]

% cat sk_redis/metadata.rb
depends "sk_chef_rewind"

% cat sk_redis/recipes/default.rb
rewind "template[#{node['redis']['**conf_dir']}/redis.conf]" do
cookbook_name "sk_redis"
end

% cat sk_redis/templates/default/*redis.conf.erb
[...redis.conf template hacked up to remove vm-
options and rename some
others...]

% cat roles/redis.rb
name "redis"
description "role for deploying redis"
override_attributes({
"redis" => {
"install_type" => "source"
}
})
run_list(
"recipe[portertech_redis::**server]",
"recipe[sk_redis]"
)

I think this is rad, Bryan. I’ve been using this pattern in cookbooks for a long time, and it never occurred to me what I was just copying ridiculous boilerplate.

Thanks!

Adam

From: Bryan Berry <bryan.berry@gmail.commailto:bryan.berry@gmail.com>
Reply-To: "chef@lists.opscode.commailto:chef@lists.opscode.com" <chef@lists.opscode.commailto:chef@lists.opscode.com>
Date: Sunday, November 11, 2012 10:52 AM
To: "chef@lists.opscode.commailto:chef@lists.opscode.com" <chef@lists.opscode.commailto:chef@lists.opscode.com>
Subject: [chef] Re: “edit” your resources in a library cookbook from an application cookbook

Dear Chef users!

chef-edit has been renamed chef-rewind https://github.com/bryanwb/chef-rewind , enjoy!

file postgresql/recipes/server.rb

user “postgres” do
uid 26
home '/home/postgres’
supports :manage_home => true
end

file my-postgresql/recipes/

require ‘chef/edit’

include_recipe “postgresql::server”

rewind "user[postgres]"
home '/var/lib/pgsql/9.2’
end

On Wed, Nov 7, 2012 at 6:51 PM, Bryan Berry <bryan.berry@gmail.commailto:bryan.berry@gmail.com> wrote:
ahead of tomorrow’s G+ hangout on Cookbook reusability, I whipped up
this little gem that embodies what I have in mind for making cookbooks
more reusable. This is alpha level code.

chef-edit essentially allows you to reopen an existing resource. It is
mostly just syntactic sugar on top of the Chef::Recipe.resources
method

https://github.com/bryanwb/chef-edit

Add this line to your application’s Gemfile:

Installation

gem 'chef-edit’
And then execute:

Or install it yourself as:

$ gem install chef-edit

Usage

file postgresql/recipes/server.rb

user “postgres” do
uid 26
home '/home/postgres’
supports :manage_home => true
end

file my-postgresql/recipes/

require ‘chef/edit’

include_recipe “postgresql::server”

edit "user[postgres]"
home '/var/lib/pgsql/9.2’
end