Accessing attributes in a resource that have been generated by other resources Re: Re: how to manage dependent resources?


#1

dear friends,

I am wading into some murky waters. You may want to comment before some of
this code pollutes your own drinking source.

jira/recipes/default.rb

tomcat “jira” do

user node[‘jira’][‘user’]

action :install

end

This tomcat LWRP determines a path for the resulting tomcat instance
depending on the attributes set in the tomcat cookbook.

following this tomcat instance I need to place various dependencies into
the tomcat instance, .war, .jar files specifically

I have done the following. The tomcat LWRP appends a attribute to the
calling cookbook

node[self.cookbook_name][‘tomcat’][‘base’] = “/usr/local/tomcat/jira”

then to grab the mysql java library, I do the following:

jira/recipes/default.rb

grabs library dependency and puts in a destination

ivy “mysql-connector-java” do

groupId “mysql”

version “5.1.18”

dest_attr “tomcat_base/lib”

end

I use the funky dest_attr attribute and parse it to be

eval( “node[’#{self.cookbook_name}’]['tomcat][‘base’] + ‘/lib’”)

Can anyone think of a better way to do this?

On Wed, Feb 29, 2012 at 10:14 AM, Bryan Berry bryan.berry@gmail.com wrote:

hedge hog, tks, unfortunately i don’t think my particular resource can be
expressed as a task or a service, and I am on RHEL :frowning:

On Wed, Feb 29, 2012 at 10:05 AM, Hedge Hog hedgehogshiatus@gmail.comwrote:

On Wed, Feb 29, 2012 at 7:53 PM, Bryan Berry bryan.berry@gmail.com
wrote:

I have an issue where I need to provide values generated dynamically by
one
resource to resources that follow it

My tomcat lwrp generates a base directory for each new instance that is
a
readable attribute “base”

Following resources will use that base attribute. In this example, the
ivy
resource should place a .jar file in the #{base}/lib directory

If you are on a system that provides upstart, then I think you’ll find
upstart will scratch that itch most effectively[0].
Of course this assumes that each of the current resources can be
expressed as a task or service.
I generally use Chef to tweak a generic upstart conf template, and use
the emit/emits/start on/stop on to look after chaining and sequencing.
If you go down this path you might have to pay attention to upstart
synchronisation[1].

HTH

[0]
http://upstart.ubuntu.com/cookbook/#run-a-job-when-a-file-or-directory-is-created-deleted
[1] http://upstart.ubuntu.com/cookbook/#synchronisation

include_recipe “ark”

include_recipe “tomcat::base”

include_recipe “ivy”

t = tomcat “jira” do

user node[‘jira’][‘user’]

action :install

end

get mysql connector

ivy “mysql-connector-java” do

groupId “mysql”

version “5.1.18”

dest “#{t.base}/lib” # evaluates to “/lib”

end

ruby_block “foobarbaz” do

block do

Chef::Log.debug("t.base is #{t.base}")    # t.base evaluates to

“/usr/local/tomcat/jira”

end

end

I have found a solution thanks to Jorge Espada, but there really should
be a
more straightforward way to do this.

t = tomcat “jira” do

user node[‘jira’][‘user’]

action :nothing

end

t.run_action :install


πόλλ’ οἶδ ἀλώπηξ, ἀλλ’ ἐχῖνος ἓν μέγα
[The fox knows many things, but the hedgehog knows one big thing.]
Archilochus, Greek poet (c. 680 BC – c. 645 BC)
http://hedgehogshiatus.com