【问题标题】:chef attributes value not getting parsed in another attribute厨师属性值未在另一个属性中解析
【发布时间】:2023-05-17 09:54:02
【问题描述】:

我将 default.rb 中的属性设置为

default[:my_app] = {
  :vol => "data02",
  :commitlog => "/foo/bar/node[:vol]/commitlog",
}

:vol 值未在 commitlog 属性中解析,我收到以下错误。

mError executing action `create` on resource 'directory[/foo/bar/node[:vol]/comitlog]'[0m

【问题讨论】:

标签: ruby attributes chef-infra


【解决方案1】:

您缺少字符串插值语法,例如y = "The value of X is #{X}."你可能想要:

default[:my_app] = {
  :vol => "data02",
  :commitlog => "/foo/bar/#{node[:vol]}/commitlog",
}

另外,请记住,如果您使一个属性依赖于另一个属性的值,您可能会在稍后覆盖node[:my_app][:vol] 并期望node[:my_app][:commitlog] 的值随之改变,但它可能不会。这些属性将被一起解析,可能在您的覆盖影响第一个之前。

【讨论】:

  • 非常感谢您的回复。即使在我使用插值语法之后,当我在配方中使用 node[:my_app][:commitlog] 时,它也会显示 /foo/bar//commitlog
  • 听起来node[:vol] 不是你想的那样,或者你错过了双引号。
【解决方案2】:

即使在我使用插值语法之后,当我在配方中使用 node[:my_app][:commitlog] 时,它也会显示 /foo/bar//commitlog

【讨论】: