1


We have recipe which use node attribute:

python_pip 'request_proxy' do
  virtualenv '/opt/proxy/.env'
  version node.default['request-proxy']['version']
  Chef::Log.info('Auth request proxy #{version}')
  action :install
end

Attribute is set on node level and everything is OK, but for test purposes i want to override it in my local (kitchen/vagrant) node. As first step i add attribute to my .kitchen.yml:

suites:
  - name: default
    run_list:
    - recipe[proxy_install]
    attributes: {request-proxy: {'version': '1.0.8'}}

Unfortunately node still use the "default" version. Everything works fine, without any error and completly ignores my attributes.
Later i tried add this to parameter file (chef-client -j params.json) on production node, result was the same.

What I missed? What am I doing wrong?

P.S. Chef::Log.info('Auth request proxy #{version}') is also completely ignored ??

parasit
  • 13
  • 6
  • `Chef::Log.info` won't be parsed inside a resource, I'm even surprised it does not raise an error as incorrect attribute. Set it out of the `python_pip` resource and it should work once you have replaced single quotes by double quote to have interpolation and `#{version}` replaced by it's value. (Comment and not answer as I've no clue about the kitchen.yml problem.) – Tensibai Nov 27 '15 at 08:54

1 Answers1

2

Can you try using YAML? kitchen.yml is not a JSON file, so I'm not sure that your JSON embedded inside it would work.

attributes:
  request-proxy: 
    version: '1.0.8'

Also, you probably should not be using node.default, unless you want to pick up the default value only (and never any overrides). If you want to use the attribute precedence (default, normal, override, force) in Chef, you should be doing:

node['request-proxy']['version']

Finally, you also have a single-quoted string with a variable. This will never work like you expect in Ruby (are you running rubocop? It would have caught this). Try it with double quotes, and remove it from the middle of your resource:

Chef::Log.info("Auth request proxy #{version}")
Martin
  • 2,815
  • 1
  • 21
  • 30
  • Hi, Thank you for answer. I'll tried YAML/JSON (both correct https://docs.chef.io/config_yml_kitchen.html), both types of quoting, without results. Problem was in word "default", without it everything works perfectly !!! P.S. Chef::Log, still is ignored :) – parasit Nov 26 '15 at 17:03
  • All valid JSON is also valid YAML :) – coderanger Nov 26 '15 at 17:10
  • This whole question is probably a dup of http://stackoverflow.com/questions/23224384/adding-attributes-to-test-kitchen – lamont Nov 26 '15 at 21:45
  • Also, the JSON is probably buggy and at least "request-proxy" should have double quotes around it, and I think the single quotes need to be converted to double quotes. But I'm not sure if the YAML-parsed-JSON is less strict than the JSON gem... – lamont Nov 26 '15 at 21:50
  • Didn't realize JSON-inside-YAML like that would work. :) – Martin Nov 27 '15 at 12:09