[chef] Re: Re: Attributes not getting set from wrapper cookbook


Chronological Thread 
  • From: millisami r < >
  • To: chef < >
  • Subject: [chef] Re: Re: Attributes not getting set from wrapper cookbook
  • Date: Wed, 11 Dec 2013 13:48:59 +0545

Thanks for the reply.
I've modified the case below.

=================================
app-cookbook
  - attributes
    default['asm']['user'] = "vagrant"
    default['asm']['deploy_to'] = "/home/#{node['asm']['user']}/myapp"
  - recipes
    - default.rb

    user node['asm']['user'] do
      password node['asm']['password']
      home "/home/#{node['asm']['user']}"
    end
---------------------------------
app-wrapper-cookbook
  - recipes
    - default.rb
    node.set['asm']['user'] = 'otheruser'
    include_recipe "app-cookbook::default"
=================================

In app-cookbook, I've another attribute `['asm']['deploy_to']` which uses the `['asm']['user']` to interpolate
the value to `['asm']['deploy_to']`.

Now running the `app-wrapper-cookbook`, the value for `['asm']['user']` is overriden with the value `otheruser`,
but the value of `['asm']['deploy_to']` still has the `vagrant` in path.
i.e. It generates `/home/vagrant/myapp` which should also have been overridden by `/home/otheruser/myapp`

Is this the way that computed attributes works?
How chef will resolve such issue?




@millisami
~Sachin Sagar Rai
Ruby on Rails Developer
http://tfm.com.np
http://nepalonrails.com


On Wed, Dec 11, 2013 at 10:44 AM, Julian C. Dunn < " target="_blank"> > wrote:
Where possible you should try to set the attributes in your wrapper
cookbook's attributes file, not the recipe itself. It is safe (and
recommended) to do so if you only have app-wrapper-cookbook in your
run list and depend on app-cookbook in metadata; app-cookbook's
attributes will get loaded first and then overridden by the wrapper.

In the wrapper's attributes file you need only do

  default['asm']['user'] = 'otheruser'

There is no need to use "set" priority. "default" will do fine, given
merge order.

Even if you want to change the attribute in recipe context, you are
modifying the attribute in the wrong order. You need to do this before
include_recipe. That's because include_recipe will compile and add the
user to the resource collection before you've had a chance to change
the attribute.

You can read http://www.getchef.com/blog/2013/12/03/doing-wrapper-cookbooks-right/
for more background & guidance on wrapper cookbooks.

regards,
Julian


On Tue, Dec 10, 2013 at 11:37 PM, millisami r < "> > wrote:
>
> Ohai! Chefs!
>
> Having issues with the attribute while developing wrapper cookbook to deploy
> the app cookbook.
> Following are the 2 cookbooks to explain the problem.
>
> =================================
> app-cookbook
>   - attributes
>     default['asm']['user'] = "vagrant"
>   - recipes
>     - default.rb
>
>     user node['asm']['user'] do
>       password node['asm']['password']
>       home "/home/#{node['asm']['user']}"
>     end
> ---------------------------------
> app-wrapper-cookbook
>   - recipes
>     - default.rb
>
>     include_recipe "app-cookbook::default"
>     node.set['asm']['user'] = 'otheruser'
> =================================
>
> When I run the `app-wrapper-cookbook`, the attribute set in wrapper cookbook
> `node.set['asm']['user'] = 'otheruser'` doesn't take effect.
> Instead it reads the value `vagrant`.
> It should have been `otheruser` ?
>
> How to solve this attribute precedence while building the wrapper cookbook ?
>
>
> @millisami
> ~Sachin Sagar Rai
> Ruby on Rails Developer
> http://tfm.com.np
> http://nepalonrails.com



--
[ Julian C. Dunn < "> >          * Sorry, I'm    ]
[ WWW: http://www.aquezada.com/staff/julian    * only Web 1.0  ]
[ gopher://sdf.org/1/users/keymaker/           * compliant!    ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9       ]




Archive powered by MHonArc 2.6.16.

§