Node.set, knife node show, and deep merging arrays


#1

If a cookbook defines attributes such as:

default[:foo] = {
:bar => %w( one )
}

And in the recipe, ‘:foo’ is explicitly set:

node.set[:foo][:bar] = %w( two )

log “node.foo.bar is #{node[:foo][:bar]}” # Logs ‘two’

Then the node gets a ‘normal’ attribute of
node.foo.bar == [‘two’]

So this is not a deep merge of node.foo.bar, but rather
an explicit ‘set’.

Which seems right, and that’s what it evaluates to in the
recipe and it’s templates.

The issue: ‘knife node show’ displays inconsistent values.

knife node show the-node --attrib foo --format json

# displays:

{

“foo”: {

“bar”: [“one”, “two”] # <- deep merge default+normal

}

}

knife node show the-node --attrib foo.bar --format json

# displays:

{ “foo.bar”: [“two”] } # the explicitly set value

Unless I’m missing something, this appears to be a bug.
‘knife node show’ with the --attrib option must display
the value of the given attribute as evaluated in the
recipe, should it not?

F