从 Chef 食谱中引用属性

Referencing attributes from within a Chef recipe

我有一个名为 default.rb 的属性文件,其中包含一个键 default['current'],它以字符串格式存储目录。我想在更改目录时将其用于以下命令:

# Run database migrations
execute 'database migrations' do
  user    'ubuntu'
  cwd     "#{default['current']}"
  command 'sudo php artisan down && sudo php artisan migrate --force && sudo php artisan up'
end

相反,当我 运行 食谱时,我得到了以下错误。

NameError
---------
No resource, method, or local variable named `default' for `Chef::Recipe "deploy"'

有没有我缺少的正确方法?我不想在工作目录中硬编码。

在配方中引用属性时,我们需要在它们前面加上node前缀,像这样:

cwd     node['current']

另请参阅:Overriding attributes in the recipe

这似乎得到了回答。但是我没有看到这个(IMO)文档的核心 link 都在这里:https://docs.chef.io/attributes.html