How does a definition know which file or template to use?

I have a definition that uses several files and templates to build a tomcat
base skeleton. When I call the definition from a recipe in another cookbook it
can not find the files nor templates as it is looking in the callers cookbooks
instead of the definitions.

Can I direct the definition to look in the correct place or is there an
idiomatically chef way of accomplishing this?

Thank you
Jono

Hi Jono,

On Thu, Oct 7, 2010 at 7:10 PM, jono@spiralarm.com wrote:

I have a definition that uses several files and templates to build a
tomcat base skeleton. When I call the definition from a recipe in
another cookbook it can not find the files nor templates as it is
looking in the callers cookbooks instead of the definitions.

Can I direct the definition to look in the correct place or is there an
idiomatically chef way of accomplishing this?

I think you want to specify the cookbook parameter in the resources in
your definition.

E.g.

define :mydef do
  template "/opt/so/and/so" do
    # stuff
    cookbook "mydef"
  end
end

Does that help? You might look at the runit cookbook in the Opscode
cookbooks repo
for an example of using (rather involved) definitions.

  • seth

comments inlined.

On 8 October 2010 14:29, Seth Falcon seth@opscode.com wrote:

Hi Jono,

On Thu, Oct 7, 2010 at 7:10 PM, jono@spiralarm.com wrote:

I have a definition that uses several files and templates to build a
tomcat base skeleton. When I call the definition from a recipe in
another cookbook it can not find the files nor templates as it is
looking in the callers cookbooks instead of the definitions.

Can I direct the definition to look in the correct place or is there an
idiomatically chef way of accomplishing this?

I think you want to specify the cookbook parameter in the resources in
your definition.

E.g.

define :mydef do
template "/opt/so/and/so" do
# stuff
cookbook "mydef"
end
end

Does that help? You might look at the runit cookbook in the Opscode
cookbooks repo
for an example of using (rather involved) definitions.

This was perfect, thank you.  I couldn't find anything in the

documentation about this, did I miss it? ( interested, not a jib :slight_smile: )

Cheers
Jono

  • seth

On Thu, Oct 7, 2010 at 10:57 PM, Jonathan Ferguson jono@spiralarm.com wrote:

define :mydef do
template "/opt/so/and/so" do
# stuff
cookbook "mydef"
end
end

Does that help? You might look at the runit cookbook in the Opscode
cookbooks repo
for an example of using (rather involved) definitions.

This was perfect, thank you.  I couldn't find anything in the

documentation about this, did I miss it? ( interested, not a jib :slight_smile: )

Yep!

http://wiki.opscode.com/display/chef/Resources#Resources-Template

Adam

--
Opscode, Inc.
Adam Jacob, CTO
T: (206) 508-7449 E: adam@opscode.com