I am trying to just log an attribute from a chef role using TestKitchen Bellow my configuration:
roles/myrole.json
{
"name": "myrole",
"json_class": "Chef::Role",
"description": "Example",
"chef_type": "role",
"default_attributes": {
"git_cookbook": {
"mykey1": "myvalue"
}
},
"run_list": [
"recipe[git_cookbook]"
]
}
git_cookbook
log "Hello World, #{node['mykey1']}" do
level :info
end
package 'git'
kitchen.yaml
---
driver:
name: vagrant
provisioner:
name: chef_zero
roles_path: ../roles
verifier:
name: inspec
platforms:
- name: ubuntu-20.04
suites:
- name: default
verifier:
inspec_tests:
- test/integration/default
run_list:
- role[myrole]
attributes:
Policyfile.rb
name 'git_cookbook'
default_source :supermarket
run_list 'role[myrole]'
cookbook 'git_cookbook', path: '.'
when I run the command: kitchen converge (or kitchen test), the value of mykey1 which "myvalue" is not logged.
....
Recipe: git_cookbook::default
log[Hello World, ] action write
....
It seems like TestKitchen is ignoring the role which I specified in both kitchen.yaml and Policyfile.rb, I tried to remove it from one or the other, none of the options worked.
Any idea why? am I missing something?
In your git_cookbook
(recipe), you are referring to the attribute: node['mykey1']
Whereas, in the roles/myrole.json
, the attribute you have effectively defined is:
node['git_cookbook']['mykey1']
Then in your recipe, you should have:
log "Hello World, #{node['git_cookbook']['mykey1']}" do
level :info
end