我正在尝试增加值并在配方中动态地在另一个资源中使用,但仍然无法做到这一点。
Chef::Log.info("I am in #{cookbook_name}::#{recipe_name} and current disk count #{node[:oracle][:asm][:test]}")
bash "beforeTest" do
code lazy{ echo #{node[:oracle][:asm][:test]} }
end
ruby_block "test current disk count" do
block do
node.set[:oracle][:asm][:test] = "#{node[:oracle][:asm][:test]}".to_i+1
end
end
bash "test" do
code lazy{ echo #{node[:oracle][:asm][:test]} }
end
但是仍然出现以下错误:
NoMethodError ------------- undefined method echo' for Chef::Resource::Bash
Cookbook Trace: ---------------
/var/chef/cache/cookbooks/Oracle11G/recipes/testSplit.rb:3:in block (2 levels) in from_file'
Resource Declaration: ---------------------
# In /var/chef/cache/cookbooks/Oracle11G/recipes/testSplit.rb
1: bash "beforeTest" do
2: code lazy{
3: echo "#{node[:oracle][:asm][:test]}"
4: }
5: end
[请您帮忙在bash中使用懒惰吗?如果不是很懒,还有其他选择吗?
bash "beforeTest" do
code lazy { "echo #{node[:oracle][:asm][:test]}" }
end
您应该引用命令以使插值生效;如果不是,ruby会搜索一个echo命令,这在ruby上下文中是未知的(因此您在日志中得到的错误)。
警告:懒惰必须针对整个资源属性;像这样的东西[[WO N'T work:
bash "beforeTest" do
code "echo node asm test is: #{lazy { node[:oracle][:asm][:test]} }"
end
懒惰的评估需要一段红宝石代码,如here所述>使用这样的
log
资源可能会得到更好的结果:
log "print before" do message lazy { "node asm test is #{node[:oracle][:asm][:test]}" } end