[chef] Re: Dynamic resource naming in recipe


Chronological Thread 
  • From: Michael Glenney < >
  • To: " " < >
  • Subject: [chef] Re: Dynamic resource naming in recipe
  • Date: Thu, 4 Sep 2014 15:25:52 -0700

I don't have an idea for getting rid of the logic all together but you couldn't you move it into the LWRP (where it belongs IMHO) to make the recipes a little cleaner?

So your deploy resource would accept application_type and instance_type as attributes.  If your data is like { "application" : { "somename" : { "instance_type" : "tomcat", "application_type": "swing" }, "anothername" { etc etc } } }

node['application'].each do |app,data|
  deploy app do
    instance_type data['instance_type']
    application_type data['application_type']
  end
end


MG


On Thu, Sep 4, 2014 at 8:59 AM, Tensibai < " target="_blank"> > wrote:

Hello alls,

I'm wondering if a resource could be made up with variables.

I've specific LWRPs called:

 

deploy_tomcat_swing

deploy_tomcat_war

deploy_jboss_swing

 

My 'applications' cookbooks define the app type (swing or war, along other types (6 at all)) and my server cookbook define the server type and the apps on this instance.

A node could have many instances too.

One requirement is to deploy on each instance the apps needed in one pass (we don't want 8 client.rb on a node, one for its system and 7 for its instances).

Actually I've a loop over the instances and a nested loop dor the app.

 

Now that I'm inside this dual loop, I know the instance type and the application type and I've something like:

 

if instance_type='tomcat' then

 case application_type

 when 'swing'

      deploy_tomcat_swing

 when [....]

end

if [...] then

 same loop as above

end

 

I think you got the idea of how hard it is to add a new packaging type for applications...

 

Now I gave the context is this something handlable to define the ressource dynamically with something like

deploy_#{instance_type}_#{application_type}

 

I did some test with send but its far from working...

If its absolutely stupid, tell me ;)

Thanks for reading till here

 

Tensibai

 

 

 




Archive powered by MHonArc 2.6.16.

§