Chef会覆盖cookbook的默认属性

时间:2017-03-28 14:31:41

标签: attributes chef

git cookbook在用于下载相应版本的网址中存在错误。 url在属性文件中设置为默认属性,所以我想我可以用静态覆盖url但它不起作用。这是来自git cookbook的代码:

case node['platform_family']
when 'windows'
  default['git']['version'] = '2.8.1'
  if node['kernel']['machine'] == 'x86_64'
    default['git']['architecture'] = '64'
    default['git']['checksum'] = '5e5283990cc91d1e9bd0858f8411e7d0afb70ce26e23680252fb4869288c7cfb'
  else
    default['git']['architecture'] = '32'
default['git']['checksum'] = '17418c2e507243b9c98db161e9e5e8041d958b93ce6078530569b8edaec6b8a4'
  end
  default['git']['url'] = 'https://github.com/git-for-windows/git/releases/download/v%{version}.windows.1/Git-%{version}-%{architecture}-bit.exe'

该cookbook作为依赖项包含在我的metadata.rb文件中,并用作我的食谱中的资源。它不是运行列表的一部分。我已经尝试覆盖我的角色文件中的URL,如此

"name": "web",
  "description": "Web Server Role.",
  "json_class": "Chef::Role",
  "default_attributes": {
    "chef_client": {
      "interval": 300,
      "splay": 60
    },
    "git": {
      "url": "a test string"
    }
  },...

这不起作用,所以我尝试将它作为默认值添加到我的配方的属性文件中,当这不起作用时,我尝试了override!方法仍然无效。

我认为问题是由于当我声明属性时该属性不存在,并且它被git配方覆盖。

我不知道怎么解决这个问题。

1 个答案:

答案 0 :(得分:1)

使用override_attributes代替default_attributes

"name": "web",
"description": "Web Server Role.",
"json_class": "Chef::Role",
"default_attributes": {
  "chef_client": {
    "interval": 300,
    "splay": 60
  }
},
"override_attributes": {
  "git": {
    "url": "a test string"
  }
},...