Customizing the templates of a community cookbook?


#1

What’s the “right” way to handle this? I’m looking to migrate over to using
Berkshelf and something that I’m coming across is that I’ve got a package
or two where I’ve customized the templates generated by a community
cookbook for my specific use (either via OS or host directories).

Is it better to create a wrapper cookbook, or is there some other way to
handle this that I’m missing? I found a previous thread on this here:
http://lists.opscode.com/sympa/arc/chef/2012-07/msg00038.html, but it looks
like whatever scenario they were referencing is no longer in the
documentation. (Not sure if it didn’t last from the wiki -> doc conversion,
or if it had been removed from the wiki prior to that.)

Thanks!


~~ StormeRider ~~

“Every world needs its heroes […] They inspire us to be better than we
are. And they protect from the darkness that’s just around the corner.”

(from Smallville Season 6x1: “Zod”)

On why I hate the phrase “that’s so lame”… http://bit.ly/Ps3uSS


#2

On Sun, May 26, 2013 at 1:24 PM, Morgan Blackthorne
stormerider@gmail.comwrote:

What’s the “right” way to handle this? I’m looking to migrate over to
using Berkshelf and something that I’m coming across is that I’ve got a
package or two where I’ve customized the templates generated by a community
cookbook for my specific use (either via OS or host directories).

Is it better to create a wrapper cookbook, or is there some other way to
handle this that I’m missing? I found a previous thread on this here:
http://lists.opscode.com/sympa/arc/chef/2012-07/msg00038.html, but it
looks like whatever scenario they were referencing is no longer in the
documentation. (Not sure if it didn’t last from the wiki -> doc conversion,
or if it had been removed from the wiki prior to that.)

I was able to load the old page using the wayback machine (
http://web.archive.org/web/20120624062311/http://wiki.opscode.com/display/chef/Templates),
but it isn’t too helpful in this case.

You’ll need a wrapper cookbook which contains your local template, with a
recipe that re-opens the resource in the original cookbook and changes its
"cookbook" parameter to point to your wrapper cookbook. Joshua Timberman
has a blog post describing this, though his example is changing service
resources:

http://jtimberman.housepub.org/blog/2012/11/19/chef-repository-berkshelf-conversion/

If you’d prefer a little sugar, the chef-rewind gem offers your exact use
case as an example: https://github.com/bryanwb/chef-rewind

Hope that helps,

Zac


#3

Actually, that’s exactly what I was looking for-- thanks! His OpenVPN
example is dead-on for what I need to do for nagios::server.

adds Joshua’s blog to their Feedly list, after the Nth time of finding
something useful on it :slight_smile:


~~ StormeRider ~~

“Every world needs its heroes […] They inspire us to be better than we
are. And they protect from the darkness that’s just around the corner.”

(from Smallville Season 6x1: “Zod”)

On why I hate the phrase “that’s so lame”… http://bit.ly/Ps3uSS

On Sun, May 26, 2013 at 5:40 AM, Zac Stevens zts@cryptocracy.com wrote:

On Sun, May 26, 2013 at 1:24 PM, Morgan Blackthorne <stormerider@gmail.com

wrote:

What’s the “right” way to handle this? I’m looking to migrate over to
using Berkshelf and something that I’m coming across is that I’ve got a
package or two where I’ve customized the templates generated by a community
cookbook for my specific use (either via OS or host directories).

Is it better to create a wrapper cookbook, or is there some other way to
handle this that I’m missing? I found a previous thread on this here:
http://lists.opscode.com/sympa/arc/chef/2012-07/msg00038.html, but it
looks like whatever scenario they were referencing is no longer in the
documentation. (Not sure if it didn’t last from the wiki -> doc conversion,
or if it had been removed from the wiki prior to that.)

I was able to load the old page using the wayback machine (
http://web.archive.org/web/20120624062311/http://wiki.opscode.com/display/chef/Templates), but it isn’t too helpful in this case.

You’ll need a wrapper cookbook which contains your local template, with a
recipe that re-opens the resource in the original cookbook and changes its
"cookbook" parameter to point to your wrapper cookbook. Joshua Timberman
has a blog post describing this, though his example is changing service
resources:

http://jtimberman.housepub.org/blog/2012/11/19/chef-repository-berkshelf-conversion/

If you’d prefer a little sugar, the chef-rewind gem offers your exact use
case as an example: https://github.com/bryanwb/chef-rewind

Hope that helps,

Zac


#4

Hi,

I used to use chef-rewind until I got the tip form Joshua to just access
the resource collection via resources().

So, I’d be interested in what’s the benefit of the chef-rewind gem?

Thanks for explaining
Steffen

On 5/26/13 2:40 PM, Zac Stevens wrote:

On Sun, May 26, 2013 at 1:24 PM, Morgan Blackthorne
stormerider@gmail.comwrote:

What’s the “right” way to handle this? I’m looking to migrate over to
using Berkshelf and something that I’m coming across is that I’ve got a
package or two where I’ve customized the templates generated by a community
cookbook for my specific use (either via OS or host directories).

Is it better to create a wrapper cookbook, or is there some other way to
handle this that I’m missing? I found a previous thread on this here:
http://lists.opscode.com/sympa/arc/chef/2012-07/msg00038.html, but it
looks like whatever scenario they were referencing is no longer in the
documentation. (Not sure if it didn’t last from the wiki -> doc conversion,
or if it had been removed from the wiki prior to that.)

I was able to load the old page using the wayback machine (
http://web.archive.org/web/20120624062311/http://wiki.opscode.com/display/chef/Templates),
but it isn’t too helpful in this case.

You’ll need a wrapper cookbook which contains your local template, with a
recipe that re-opens the resource in the original cookbook and changes its
"cookbook" parameter to point to your wrapper cookbook. Joshua Timberman
has a blog post describing this, though his example is changing service
resources:

http://jtimberman.housepub.org/blog/2012/11/19/chef-repository-berkshelf-conversion/

If you’d prefer a little sugar, the chef-rewind gem offers your exact use
case as an example: https://github.com/bryanwb/chef-rewind

Hope that helps,

Zac


#5

This should also serve as a call to folks to make the templates used an
attribute where possible/where it makes sense:

https://github.com/lusis/chef-logstash/blob/master/attributes/kibana.rb#L3

On Sun, May 26, 2013 at 8:40 AM, Zac Stevens zts@cryptocracy.com wrote:

On Sun, May 26, 2013 at 1:24 PM, Morgan Blackthorne <stormerider@gmail.com

wrote:

What’s the “right” way to handle this? I’m looking to migrate over to
using Berkshelf and something that I’m coming across is that I’ve got a
package or two where I’ve customized the templates generated by a community
cookbook for my specific use (either via OS or host directories).

Is it better to create a wrapper cookbook, or is there some other way to
handle this that I’m missing? I found a previous thread on this here:
http://lists.opscode.com/sympa/arc/chef/2012-07/msg00038.html, but it
looks like whatever scenario they were referencing is no longer in the
documentation. (Not sure if it didn’t last from the wiki -> doc conversion,
or if it had been removed from the wiki prior to that.)

I was able to load the old page using the wayback machine (
http://web.archive.org/web/20120624062311/http://wiki.opscode.com/display/chef/Templates), but it isn’t too helpful in this case.

You’ll need a wrapper cookbook which contains your local template, with a
recipe that re-opens the resource in the original cookbook and changes its
"cookbook" parameter to point to your wrapper cookbook. Joshua Timberman
has a blog post describing this, though his example is changing service
resources:

http://jtimberman.housepub.org/blog/2012/11/19/chef-repository-berkshelf-conversion/

If you’d prefer a little sugar, the chef-rewind gem offers your exact use
case as an example: https://github.com/bryanwb/chef-rewind

Hope that helps,

Zac


#6

Hi Steffen,

On Sun, May 26, 2013 at 3:47 PM, Steffen Gebert st+gmane@st-g.de wrote:

I used to use chef-rewind until I got the tip form Joshua to just access
the resource collection via resources().

So, I’d be interested in what’s the benefit of the chef-rewind gem?

Functionally, there’s no benefit/difference - it’s just a little “syntactic
sugar”. Some people may prefer chef-rewind’s syntax, even when they know
how to do it directly. Similarly, ruby-averse Chef users may find it a
little easier to use; a shallower learning curve makes a big difference in
some teams.

Zac


#7

So after some more research, it looks like my particular case is a little
more complicated than I thought. While the nagios::server recipe ends up
using templates in the end, these are done via the nagios_conf definition:

define :nagios_conf, :variables => {}, :config_subdir => true do

conf_dir = params[:config_subdir] ? node[‘nagios’][‘config_dir’] :
node[‘nagios’][‘conf_dir’]

template “#{conf_dir}/#{params[:name]}.cfg” do
owner node[‘nagios’][‘user’]
group node[‘nagios’][‘group’]
source "#{params[:name]}.cfg.erb"
mode 00644
variables params[:variables]
notifies :reload, "service[nagios]"
backup 0
end
end

I’m not sure how to override a definition.


~~ StormeRider ~~

“Every world needs its heroes […] They inspire us to be better than we
are. And they protect from the darkness that’s just around the corner.”

(from Smallville Season 6x1: “Zod”)

On why I hate the phrase “that’s so lame”… http://bit.ly/Ps3uSS

On Sun, May 26, 2013 at 1:45 PM, Zac Stevens zts@cryptocracy.com wrote:

Hi Steffen,

On Sun, May 26, 2013 at 3:47 PM, Steffen Gebert st+gmane@st-g.de wrote:

I used to use chef-rewind until I got the tip form Joshua to just access
the resource collection via resources().

So, I’d be interested in what’s the benefit of the chef-rewind gem?

Functionally, there’s no benefit/difference - it’s just a little
"syntactic sugar". Some people may prefer chef-rewind’s syntax, even when
they know how to do it directly. Similarly, ruby-averse Chef users may
find it a little easier to use; a shallower learning curve makes a big
difference in some teams.

Zac


#8

You have to override template[#{conf_dir}/#{params[:name]}.cfg]

On 5/27/13 4:25 PM, Morgan Blackthorne wrote:

So after some more research, it looks like my particular case is a little
more complicated than I thought. While the nagios::server recipe ends up
using templates in the end, these are done via the nagios_conf definition:

define :nagios_conf, :variables => {}, :config_subdir => true do

conf_dir = params[:config_subdir] ? node[‘nagios’][‘config_dir’] :
node[‘nagios’][‘conf_dir’]

template “#{conf_dir}/#{params[:name]}.cfg” do
owner node[‘nagios’][‘user’]
group node[‘nagios’][‘group’]
source "#{params[:name]}.cfg.erb"
mode 00644
variables params[:variables]
notifies :reload, "service[nagios]"
backup 0
end
end

I’m not sure how to override a definition.


~~ StormeRider ~~

“Every world needs its heroes […] They inspire us to be better than we
are. And they protect from the darkness that’s just around the corner.”

(from Smallville Season 6x1: “Zod”)

On why I hate the phrase “that’s so lame”… http://bit.ly/Ps3uSS

On Sun, May 26, 2013 at 1:45 PM, Zac Stevens zts@cryptocracy.com wrote:

Hi Steffen,

On Sun, May 26, 2013 at 3:47 PM, Steffen Gebert st+gmane@st-g.de wrote:

I used to use chef-rewind until I got the tip form Joshua to just access
the resource collection via resources().

So, I’d be interested in what’s the benefit of the chef-rewind gem?

Functionally, there’s no benefit/difference - it’s just a little
"syntactic sugar". Some people may prefer chef-rewind’s syntax, even when
they know how to do it directly. Similarly, ruby-averse Chef users may
find it a little easier to use; a shallower learning curve makes a big
difference in some teams.

Zac