无法使用 TestKitchen 解析厨师角色

Unable to resolve chef roles with TestKitchen

我正在尝试使用 TestKitchen 记录厨师角色的属性 下面是我的配置:

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: '.'

当我 运行 命令:kitchen converge(或 kitchen test)时,mykey1 的值“myvalue”未被记录。

 ....
 Recipe: git_cookbook::default
 log[Hello World, ] action write 
 ....

似乎 TestKitchen 忽略了我在 kitchen.yaml 和 Policyfile.rb 中指定的角色,我试图从一个或另一个中删除它,none 个选项有效.

知道为什么吗?我错过了什么吗?

在您的 git_cookbook(配方)中,您指的是属性:node['mykey1']

而在 roles/myrole.json 中,您有效定义的属性是:

node['git_cookbook']['mykey1']

那么在你的食谱中,你应该有:

log "Hello World, #{node['git_cookbook']['mykey1']}" do
  level :info
end