[chef] Re: Re: Dynamic resource naming in recipe


Chronological Thread 
  • From: Tensibai < >
  • To:
  • Subject: [chef] Re: Re: Dynamic resource naming in recipe
  • Date: Fri, 05 Sep 2014 09:44:51 +0200

Under the hood each of my lwrp call artifact_deploy with slighty diferent parameters, this chages was in the recipe at first, so we did split it in different lwrp to avoid side effects when an update is made for one type.

My data are like:

{ "app1": { "type": "swing", [...] } }

{ "instances":["instance1": { "type": "tomcat", "apps": ["app1","app2"], [...] }, "instance2": {[...]}] }

 

I just wonder if I can found a more cosmetic way than the parse tree ;)

 

Le 2014-09-05 00:25, Michael Glenney a écrit :

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

§