Search code examples
jsonattributesoverridingchef-infratest-kitchen

Chef - override node attribute



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 ??


Solution

  • 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}")