Search code examples
chef-infratest-kitchen

Kitchen attributes only working on one platform


I am having a problem with my .kitchen.yml file. I want my attributes to be loaded for all my platforms but instead it is only being loaded for one of my platforms. This is what my .kitchen.yml file contents look like:

.kitchen.yml
---
driver:
  name: vagrant
  gui: true

provisioner:
  name: chef_zero

transport:
  name: winrm
  elevated: true

platforms:
  - name: win2012r2-standard
    driver:
      box: eltuko/win2012r2-chef-pester
      customize:
        memory: 2048
  - name: win2008r2-standard
    driver:
      box: charris/windows-2008-r2-x64
      customize:
        memory: 2048

suites:
  - name: default
    run_list:
      - recipe[xxx]
      - recipe[yyy]
    attributes:
      web:
        app:
          name: "MyApp"
          zip: "MyApp.zip"
      chef_client:
        config:
          log_level: ":debug"

Need more context?

My cookbook requires 2 attributes to be set in order for it to work. By default these attribute values are set to nil.

attributes/default.rb
default['web']['app']['name'] = nil
default['web']['app']['zip'] = nil

My default recipe checks, at the beginning, if the attributes are set before continuing the script, I do this using the following:

recipes/default.rb
ruby_block 'Check if node is configured correctly' do
  block do
    raise 'app name is not set.' if node['web']['app']['name'].nil?
    raise 'app zip is not set.' if node['web']['app']['zip'].nil?
  end
end

When I run kitchen converge, kitchen launches my Windows Server 2012 R2 VM and deploys my application successfully (the attributes work). Once that platform is done, kitchen then starts the procedure all over again for my Windows Server 2008 R2 VM. Although, at this point it throws the exception I created in my recipes/default.rb file.

I get the following error only on my Windows Server 2008 R2 VM:

console log
================================================================================
Error executing action `run` on resource 'ruby_block[Check if node is configured correctly]'
================================================================================

    RuntimeError
    ------------
    app name is not set.

Solution

  • Copying this down since it was the answer: when you add, remove, or change attribute data on a test instance you need to destroy and recreate that instance. Attribute data gets collected and cached during the create phase, so simply re-running converge won't do anything.