To use attributes or resource properties to coordinate between resources?


#1

Hi,

So we are just starting out using Chef and come across a scenario
where we are needing to configure one resource based on the parameters
of another resource. So we have defined a "glassfish_domain"
resource/provider combo. One of the properties is that port on which
it can be administered. Among other things you need this port to
administer the server so when we are connecting to the admin console
from another provider (i.e. to deploy an application) we are doing
something like;

new_resource.domain_name is the name of the domain we want to deploy to

port = new_resource.resources(:glassfish_domain =>
new_resource.domain_name).admin_port

Is accessing properties on other resources the “right” way of doing
things or should we we set attributes in the recipe that creates the
domain? As some of these values are synthesized during the creation of
the domain it is not going to be something we can access from a data
bag or the like.


Cheers,

Peter Donald


#2

Sharing attributes this way is definitely a “right” way to do it.
You’ll want to use search to find the node that has the attributes you
need to key off of, rather than hard-code the values in case the node
disappears for some reason. Having a node that depends on another is
pretty common, just don’t use hard-coded values and you’re good to go.
Start here and you’ll find lots of other examples in the cookbooks.
http://wiki.opscode.com/display/chef/Search#Search-UsingSearchinRecipes

Thanks,
Matt Ray
Senior Technical Evangelist | Opscode Inc.
matt@opscode.com | (512) 731-2218
Twitter, IRC, GitHub: mattray

On Thu, Nov 24, 2011 at 8:17 PM, Peter Donald peter@realityforge.org wrote:

Hi,

So we are just starting out using Chef and come across a scenario
where we are needing to configure one resource based on the parameters
of another resource. So we have defined a "glassfish_domain"
resource/provider combo. One of the properties is that port on which
it can be administered. Among other things you need this port to
administer the server so when we are connecting to the admin console
from another provider (i.e. to deploy an application) we are doing
something like;

new_resource.domain_name is the name of the domain we want to deploy to

port = new_resource.resources(:glassfish_domain =>
new_resource.domain_name).admin_port

Is accessing properties on other resources the “right” way of doing
things or should we we set attributes in the recipe that creates the
domain? As some of these values are synthesized during the creation of
the domain it is not going to be something we can access from a data
bag or the like.


Cheers,

Peter Donald