1

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.
Matthew
  • 146
  • 2
  • 9
  • 4
    If you added the attribute data after creating the VM, make sure you run a full destroy and re-create cycle (i.e. `kitchen test`). Otherwise what you have looks correct. – coderanger Oct 11 '16 at 21:39
  • 1
    @coderanger Wow! Thank you, running `kitchen test` worked! I also tested it with a `kitchen destroy 2008` then a `kitchen converge 2008`, worked like a charm! I was just so thrown off why the `Windows Server 2012 R2` was working but not the `Windows Server 2008 R2`. Thanks! +1 – Matthew Oct 11 '16 at 22:22

1 Answers1

3

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.

coderanger
  • 52,400
  • 4
  • 52
  • 75
  • I've noticed existing attributes being cached when using vagrant driver. Adding new attributes works, changing existing whether after they were added, or original ones, does not update attributes value. It is not a problem with dokken driver, however. – anapsix Sep 11 '19 at 15:59