我创建了一个新的CHEF Cookbook,在属性文件夹中,我将以下值添加到默认的attribute.rb文件中
********
node.default['main']['a2'] = "hello world"
********
在厨师食谱中,我想回应或创建一个名为" hello world"
该食谱有以下几行:
# Recipe:: default<br>
#<br>
# Copyright (c) 2018 The Authors, All Rights Reserved.<br>
execute 'just_test' do <br>
command 'touch /tmp/a2345' <br>
end <br>
execute 'just_test1' do <br>
command "touch /tmp/node['main']['a2']" <br>
end <br>
execute 'just_test2' do <br>
command "echo node['main']['a2']" <br>
end <br>
虽然配方成功,但我没有看到带有&#34; hello world&#34;
的文件 recipe: a2::default
* execute[just_test] action run
- execute touch /tmp/a2345
* execute[just_test1] action run
- execute touch /tmp/node['main']['a2']
* execute[just_test2] action run
- execute echo node['main']['a2']
[2018-04-03T15:52:18+00:00] WARN: Skipping final node save because override_runlist was given
在tmp目录中创建以下文件
a2345节点[main] [a2]
我们如何在CHEF配方中进行属性替换? 是否有替代方案来实现此功能
谢谢
答案 0 :(得分:2)
"touch /tmp/#{node['main']['a2']}"
- 外部双引号很重要。