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


Chronological Thread 
  • From: Tensibai < >
  • To:
  • Subject: [chef] Re: Re: Re: Dynamic resource naming in recipe
  • Date: Wed, 10 Sep 2014 12:36:55 +0200

Well, I found a way for this, so sharing for others if it could help (If I find time I'll write something better formatted)

 

node['instance'].each do |instance,params|

  params['apps'].each do |app|

    send("deploy_app_#{params['type']}_#{node['apps_definitions'][app]['type']}", app) do |r|

      r.instance_name isntance
      r.owner node['apps_definitions'][app]['owner']
      r.group node['apps_definitions'][app]['group']
    end

  end

end

 

If someone find a reason to NOT do that, please tell me.

 

Le 2014-09-05 09:44, Tensibai a écrit :

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.

§