1

I have a simple attributes file: attributes/default.rb.

default['simpleattr'] = 'file value'

And inside kitchen.yml, I do

suites:
  - name: default
    run_list: 
      - recipe[simple::default]
    attributes:
     simpleattr: 'value from kitchen'
     simple:
       simpleattr: 'value from kitchen'

Inside the recipe, I do :

log  "default['simpleattr']: "+node.default['simpleattr']

And I always get 'file value' rather than 'value from kitchen' as output.

I want to override the value in tests.

StephenKing
  • 36,187
  • 11
  • 83
  • 112
OBender
  • 2,492
  • 2
  • 20
  • 33
  • 1
    To access the value that you define in test-kitchen, you would need to access `node['simple']['simpleattr']`. Don't access attributes via `node.default`, but `node['simpleattr'] instead. In the YAML, the lines below `attributes` line lack one space indentation. You can verify that the YAML is parsed correctly via `kitchen diagnose`. – StephenKing Aug 08 '16 at 19:27
  • 1
    I hope I got the root of the problem (see my answer) – StephenKing Aug 08 '16 at 19:33
  • 1
    You were happily ignoring everything that I wrote in my comment.. – StephenKing Aug 09 '16 at 06:39

1 Answers1

4

Don't access node values through node.default[], but use node[] instead. Chef's attribute hierarchy automatically calculates the values according to its precedence levels.

I've reproduced your issue and uploaded it here on Github. The solution is as also previously described in my comment. Don't use

node.default['simpleattr']

but instead

node['simpleattr']

Then everything is as you expect and the output is

Recipe: simple::default
  * log[default['simpleattr']: value from kitchen] action write
StephenKing
  • 36,187
  • 11
  • 83
  • 112