What does node['foo'].push('bar') equate to?


The slack_handler cookbook sets an attribute like so:


Is “name” an array? What would the equivalent hierarchy look like in a role?

node['foo']['bar']['derp'] = 42

I’m assuming it would be this:

"foo": {
  "bar": [{
     "derp": 42 

I’m trying to test this in chef-shell, but I get the following error.

chef (12.8.1)> node.default['foo']
 => {}
chef (12.8.1)> node.default['foo'].push('bar')
NoMethodError: Undefined node attribute or method `push' on `node'. To set an attribute, use `push=value' instead.


You can’t automagically create an array in ruby like that. You could do something like:

node['foo']['bar'] = []
node['foo']['bar'].push( { 'derp' => 42 } )

To get:

"foo": {
  "bar": [{
     "derp": 42 


So is the readme wrong on this handler?

Add webhook1 URL

node[‘chef_client’][‘handler’][‘slack’][‘webhooks’][‘webhook1’][‘url’] = ‘https://hooks.slack.com/1/2/3

Add webhook2 URL

node[‘chef_client’][‘handler’][‘slack’][‘webhooks’][‘webhook2’][‘url’] = ‘https://hooks.slack.com/1/2/4


Sorry, updated that post in discourse, my code was off :slight_smile:

Tact is the ability to tell a man he has an open mind when he has a hole in
his head.


No, it is fine because of https://github.com/rackspace-cookbooks/chef-slack_handler/blob/master/attributes/default.rb#L26


so, in a recipe it would look like:

#node[‘chef_client’][‘handler’][‘slack’][‘webhooks’][‘name’][0] == ‘webhook1’