Including other recipes ... why the alternate format/method?

Greetings,

I am looking at a recipe for installing tomcat and happened across this line
(with associated comment):

required for the secure_password method from the openssl cookbook

::Chef::Recipe.send(:include, Opscode::OpenSSL::Password)

I was wondering why the author would choose to use this alternate way of
including a recipe. Why would they not just do something like: include_recipe
’X::Password’.

Is this not doing exactly that, simply including another recipe? If so, then
why choose the more difficult to read/maintain/etc way of doing it?

Thanks in advance for the insight!

So in this case they are not including a recipe named ‘Password’ they are including a module named ‘Password’

The module is defined in: https://github.com/opscode-cookbooks/openssl/blob/master/libraries/secure_password.rb

-----Original Message-----
From: ppavlovich@kronos.com
Sent: Wednesday, March 12, 2014 12:17pm
To: chef@lists.opscode.com
Subject: [chef] Including other recipes … why the alternate format/method?

Greetings,

I am looking at a recipe for installing tomcat and happened across this line
(with associated comment):

required for the secure_password method from the openssl cookbook

::Chef::Recipe.send(:include, Opscode::OpenSSL::Password)

I was wondering why the author would choose to use this alternate way of
including a recipe. Why would they not just do something like: include_recipe
’X::Password’.

Is this not doing exactly that, simply including another recipe? If so, then
why choose the more difficult to read/maintain/etc way of doing it?

Thanks in advance for the insight!

And I beleive you're in an instance of Chef::Recipe when you do that,
and you want to add the methods to the class as instance variables,
that way you can use the methods in all Chef::Recipe instances. So
you're sending the "include Opscode::OpenSSL::Password" message to the
Chef::Recipe class in order to do that. Its just some necessary
pure-ruby in order to do what you want to make methods directly
available in your cookbook recipes.

On Wed Mar 12 09:52:33 2014, Justin Witrick wrote:

So in this case they are not including a recipe named 'Password' they
are including a module named 'Password'

The module is defined
in: https://github.com/opscode-cookbooks/openssl/blob/master/libraries/secure_password.rb

-----Original Message-----
From: ppavlovich@kronos.com
Sent: Wednesday, March 12, 2014 12:17pm
To: chef@lists.opscode.com
Subject: [chef] Including other recipes ... why the alternate
format/method?

Greetings,

I am looking at a recipe for installing tomcat and happened across
this line
(with associated comment):

required for the secure_password method from the openssl cookbook

::Chef::Recipe.send(:include, Opscode::OpenSSL::Password)

I was wondering why the author would choose to use this alternate way of
including a recipe. Why would they not just do something like:
include_recipe
'X::Password'.

Is this not doing exactly that, simply including another recipe? If
so, then
why choose the more difficult to read/maintain/etc way of doing it?

Thanks in advance for the insight!

I explained this in my "demystifying common Chef idioms" blog post;
let me know if that answers it.

  • Julian

On Wed, Mar 12, 2014 at 12:17 PM, ppavlovich@kronos.com wrote:

Greetings,

I am looking at a recipe for installing tomcat and happened across this line
(with associated comment):

required for the secure_password method from the openssl cookbook

::Chef::Recipe.send(:include, Opscode::OpenSSL::Password)

I was wondering why the author would choose to use this alternate way of
including a recipe. Why would they not just do something like: include_recipe
'X::Password'.

Is this not doing exactly that, simply including another recipe? If so, then
why choose the more difficult to read/maintain/etc way of doing it?

Thanks in advance for the insight!

--
[ Julian C. Dunn jdunn@aquezada.com * Sorry, I'm ]
[ WWW: http://www.aquezada.com/staff/julian * only Web 1.0 ]
[ gopher://sdf.org/1/users/keymaker/ * compliant! ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9 ]