我正在尝试更改一个资源中的属性,并希望在另一资源中使用更新后的值,但更新后的值未反映在另一资源中。请帮我
Code
node[:oracle][:asm][:disks].each_key do |disk|
Chef::Log.info("I am in #{cookbook_name}::#{recipe_name} and current disk count #{node[:oracle][:asm][:test]}")
bash "beforeTest" do
code <<-EOH
echo #{node[:oracle][:asm][:test]}
EOH
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 <<-EOH
echo #{node[:oracle][:asm][:test]}
EOH
end
end
我试图更新的值是存储在node[:oracle][:asm][:test]
你的问题是code
变量是在 Chef 的编译阶段、Ruby 块更改属性值之前设置的。您需要在代码块周围添加一个惰性初始化程序。
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
第一个块实际上并不需要惰性,但我将其放入其中,以防其他地方的值也发生变化。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)