[chef] Re: Re: Re: how to manage dependent resources?


Chronological Thread 
  • From: Seth Chisamore < >
  • To:
  • Subject: [chef] Re: Re: Re: how to manage dependent resources?
  • Date: Wed, 29 Feb 2012 11:40:17 -0500
  • Authentication-results: mr.google.com; spf=pass (google.com: domain of designates 10.100.213.8 as permitted sender)

Another option we be an additional attribute on your tomcat resource that takes in a list of key/value pairs of ivy 'packages' to install:

tomcat "jira" do
  user node['jira']['user']
  dependencies 'mysql' => '5.1.18', 'foo' => '1.0.0'
  action :install                                       
end

Basically the provider for 'tomcat' would use the ivy LWRP under the covers to install everything.

Fun thing here is you could add support for other java dependency managers like maven relatively easy:

tomcat "jira" do
  user node['jira']['user']
  dependencies 'commons-lang' => '2.0'
  dependency_manager :maven
  action :install                                       
end

-- 
Seth Chisamore
Software Development Engineer, Opscode, Inc.
IRC, Skype, Twitter, Github: schisamo

On Wednesday, February 29, 2012 at 10:55 AM, Bryan Berry wrote:

that's a good idea Andrea but I really like the solution that ssd7 came up w/ 

I generate the base inside the initialize method for my tomcat LWRP

file: tomcat/resources/default.rb

def initialize(*args)s                                                                                                                        
  super                                                                                                                                       
  @action = ":install"                                                                                                                          
  catalina_parent = Pathname.new(node['tomcat']['home']).parent.to_s                                                                          
  @base = "#{catalina_parent}/ "                                                                                                       
  Chef::Log.debug("base_is ")                                                                                                         
  @supports = {:report => true, :exception => true}                                                                                           
end  

now my recipe code looks like this

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"                                                                                                                       
end      

much more elegant

thanks a lot SSD!



On Wed, Feb 29, 2012 at 4:22 PM, Andrea Campi < "> > wrote:
On Wed, Feb 29, 2012 at 9:53 AM, Bryan Berry < "> > 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
>
>
> 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


The ivy provider should be able to retrieve the tomcat resource by
name, and then access any attribute.

So something like this:

ivy "mysql" do
 groupId "mysql"
 version "5.1.18"
 base_resource :tomcat => "jira"
end

And then in the ivy provider do:

parent = resources(new_resource.base_resource)
parent.base


That's off the top of my head so YMMV

Andrea





Archive powered by MHonArc 2.6.16.

§