Array attributes merge

Hi guys!

According to this:
http://docs.opscode.com/essentials_node_object_deep_merge.html#addition

Array attributes are merged, i have checked out that this is the behaviour
when using default attributes on attribute files and roles.

But when i try to define a default attribute on one recipe:

node.default[‘foo’] = [‘bar’]

The one that i have already on defaults.rb attribute file:

node.default[‘foo’] = [‘littlebar’]

Is overrided by the one i defined on the recipe, resulting node[‘foo’] =
[‘bar’]

Defining on a role:

default_attributes (:foo => [‘bar’])

Works as expected, and results on node[‘foo’] = [‘littlebar’,‘bar’]

So what exactly node.default[‘x’] = value do on recipes? Looks like a
direct override… O_o


Si necesitas una máquina para hacer algo y no la compras al final te darás
cuenta de que has pagado lo mismo y no tienes la máquina.–Henry Ford

Alberto

I don't have a complete answer but I know that:

  1. The doc you linked to specifically calls out roles and environments. Might be a clue
  2. When writing a provider for a cookbook attributes are mutable. So maybe this will work for you within a recipe:

node.default['foo'] << 'bar'

Sent from my iPhone

On Oct 21, 2013, at 5:22 AM, "aL." ocholetrasaleatorias@gmail.com wrote:

Hi guys!

According to this: http://docs.opscode.com/essentials_node_object_deep_merge.html#addition

Array attributes are merged, i have checked out that this is the behaviour when using default attributes on attribute files and roles.

But when i try to define a default attribute on one recipe:

node.default['foo'] = ['bar']

The one that i have already on defaults.rb attribute file:

node.default['foo'] = ['littlebar']

Is overrided by the one i defined on the recipe, resulting node['foo'] = ['bar']

Defining on a role:

default_attributes (:foo => ['bar'])

Works as expected, and results on node['foo'] = ['littlebar','bar']

So what exactly node.default['x'] = value do on recipes? Looks like a direct override... O_o

--
Si necesitas una máquina para hacer algo y no la compras al final te darás cuenta de que has pagado lo mismo y no tienes la máquina.--Henry Ford
Alberto

My experience with this issue was similar, however I found that << doesn't
play nice with the autovivification.
Consequently I've been using this pattern as a workaround:

node.default['foo'] = node['foo'].to_a.push('bar')

Regards,
Luke

On 21 October 2013 16:04, Michael Glenney mike.glenney@gmail.com wrote:

I don't have a complete answer but I know that:

  1. The doc you linked to specifically calls out roles and environments.
    Might be a clue
  2. When writing a provider for a cookbook attributes are mutable. So
    maybe this will work for you within a recipe:

node.default['foo'] << 'bar'

Sent from my iPhone

On Oct 21, 2013, at 5:22 AM, "aL." ocholetrasaleatorias@gmail.com wrote:

Hi guys!

According to this:
http://docs.opscode.com/essentials_node_object_deep_merge.html#addition

Array attributes are merged, i have checked out that this is the behaviour
when using default attributes on attribute files and roles.

But when i try to define a default attribute on one recipe:

node.default['foo'] = ['bar']

The one that i have already on defaults.rb attribute file:

node.default['foo'] = ['littlebar']

Is overrided by the one i defined on the recipe, resulting node['foo'] =
['bar']

Defining on a role:

default_attributes (:foo => ['bar'])

Works as expected, and results on node['foo'] = ['littlebar','bar']

So what exactly node.default['x'] = value do on recipes? Looks like a
direct override... O_o

--
Si necesitas una máquina para hacer algo y no la compras al final te darás
cuenta de que has pagado lo mismo y no tienes la máquina.--Henry Ford

Alberto

Even += works in order to append values he he.

May be that recipes attr definitions just override attr files ones.

Mike: I have checked out that arrays merge works well on defaults attr
files + defaults on role. So environment and roles examples on the link,
are just examples, i think.

Can a opscode dev, explain what is the exactly behaviour with arrays on
attributes? Looks like it depends where you define the attr override works
as expected o_O
El 21/10/2013 16:22, "Luke Bradbury" luke.dolman@gmail.com escribió:

My experience with this issue was similar, however I found that << doesn't
play nice with the autovivification.
Consequently I've been using this pattern as a workaround:

node.default['foo'] = node['foo'].to_a.push('bar')

Regards,
Luke

On 21 October 2013 16:04, Michael Glenney mike.glenney@gmail.com wrote:

I don't have a complete answer but I know that:

  1. The doc you linked to specifically calls out roles and environments.
    Might be a clue
  2. When writing a provider for a cookbook attributes are mutable. So
    maybe this will work for you within a recipe:

node.default['foo'] << 'bar'

Sent from my iPhone

On Oct 21, 2013, at 5:22 AM, "aL." ocholetrasaleatorias@gmail.com
wrote:

Hi guys!

According to this:
http://docs.opscode.com/essentials_node_object_deep_merge.html#addition

Array attributes are merged, i have checked out that this is the
behaviour when using default attributes on attribute files and roles.

But when i try to define a default attribute on one recipe:

node.default['foo'] = ['bar']

The one that i have already on defaults.rb attribute file:

node.default['foo'] = ['littlebar']

Is overrided by the one i defined on the recipe, resulting node['foo'] =
['bar']

Defining on a role:

default_attributes (:foo => ['bar'])

Works as expected, and results on node['foo'] = ['littlebar','bar']

So what exactly node.default['x'] = value do on recipes? Looks like a
direct override... O_o

--
Si necesitas una máquina para hacer algo y no la compras al final te
darás cuenta de que has pagado lo mismo y no tienes la máquina.--Henry Ford

Alberto

Arrays and Chef Attributes – Noah Kantrowitz goes over this in great detail :slight_smile:

--Noah

On Oct 21, 2013, at 11:27 PM, "aL." ocholetrasaleatorias@gmail.com wrote:

Even += works in order to append values he he.

May be that recipes attr definitions just override attr files ones.

Mike: I have checked out that arrays merge works well on defaults attr files + defaults on role. So environment and roles examples on the link, are just examples, i think.

Can a opscode dev, explain what is the exactly behaviour with arrays on attributes? Looks like it depends where you define the attr override works as expected o_O

El 21/10/2013 16:22, "Luke Bradbury" luke.dolman@gmail.com escribió:
My experience with this issue was similar, however I found that << doesn't play nice with the autovivification.
Consequently I've been using this pattern as a workaround:

node.default['foo'] = node['foo'].to_a.push('bar')

Regards,
Luke

On 21 October 2013 16:04, Michael Glenney mike.glenney@gmail.com wrote:
I don't have a complete answer but I know that:

  1. The doc you linked to specifically calls out roles and environments. Might be a clue
  2. When writing a provider for a cookbook attributes are mutable. So maybe this will work for you within a recipe:

node.default['foo'] << 'bar'

Sent from my iPhone

On Oct 21, 2013, at 5:22 AM, "aL." ocholetrasaleatorias@gmail.com wrote:

Hi guys!

According to this: http://docs.opscode.com/essentials_node_object_deep_merge.html#addition

Array attributes are merged, i have checked out that this is the behaviour when using default attributes on attribute files and roles.

But when i try to define a default attribute on one recipe:

node.default['foo'] = ['bar']

The one that i have already on defaults.rb attribute file:

node.default['foo'] = ['littlebar']

Is overrided by the one i defined on the recipe, resulting node['foo'] = ['bar']

Defining on a role:

default_attributes (:foo => ['bar'])

Works as expected, and results on node['foo'] = ['littlebar','bar']

So what exactly node.default['x'] = value do on recipes? Looks like a direct override... O_o

--
Si necesitas una máquina para hacer algo y no la compras al final te darás cuenta de que has pagado lo mismo y no tienes la máquina.--Henry Ford
Alberto

Hi Noah!

I have read it ofc. But the thing is that array attributes dont are
set-unioned when you define the attr on a recipe. That is the thing.

When you use roles + defaults.rb file it works as you say on your blog. But
when using defaults.rb file and recipe attrs, it doesnt work!

--
Si necesitas una máquina para hacer algo y no la compras al final te darás
cuenta de que has pagado lo mismo y no tienes la máquina.--Henry Ford

Alberto

On Tue, Oct 22, 2013 at 7:32 AM, Noah Kantrowitz noah@coderanger.netwrote:

Arrays and Chef Attributes – Noah Kantrowitz goes over this in great
detail :slight_smile:

--Noah

On Oct 21, 2013, at 11:27 PM, "aL." ocholetrasaleatorias@gmail.com
wrote:

Even += works in order to append values he he.

May be that recipes attr definitions just override attr files ones.

Mike: I have checked out that arrays merge works well on defaults attr
files + defaults on role. So environment and roles examples on the link,
are just examples, i think.

Can a opscode dev, explain what is the exactly behaviour with arrays on
attributes? Looks like it depends where you define the attr override works
as expected o_O

El 21/10/2013 16:22, "Luke Bradbury" luke.dolman@gmail.com escribió:
My experience with this issue was similar, however I found that <<
doesn't play nice with the autovivification.
Consequently I've been using this pattern as a workaround:

node.default['foo'] = node['foo'].to_a.push('bar')

Regards,
Luke

On 21 October 2013 16:04, Michael Glenney mike.glenney@gmail.com
wrote:
I don't have a complete answer but I know that:

  1. The doc you linked to specifically calls out roles and environments.
    Might be a clue
  2. When writing a provider for a cookbook attributes are mutable. So
    maybe this will work for you within a recipe:

node.default['foo'] << 'bar'

Sent from my iPhone

On Oct 21, 2013, at 5:22 AM, "aL." ocholetrasaleatorias@gmail.com
wrote:

Hi guys!

According to this:
http://docs.opscode.com/essentials_node_object_deep_merge.html#addition

Array attributes are merged, i have checked out that this is the
behaviour when using default attributes on attribute files and roles.

But when i try to define a default attribute on one recipe:

node.default['foo'] = ['bar']

The one that i have already on defaults.rb attribute file:

node.default['foo'] = ['littlebar']

Is overrided by the one i defined on the recipe, resulting node['foo']
= ['bar']

Defining on a role:

default_attributes (:foo => ['bar'])

Works as expected, and results on node['foo'] = ['littlebar','bar']

So what exactly node.default['x'] = value do on recipes? Looks like a
direct override... O_o

--
Si necesitas una máquina para hacer algo y no la compras al final te
darás cuenta de que has pagado lo mismo y no tienes la máquina.--Henry Ford
Alberto