gpt4 book ai didi

ruby - 如何将值(value)从一种资源传递到 Chef Recipe 中的另一种资源?

转载 作者:数据小太阳 更新时间:2023-10-29 07:49:42 24 4
gpt4 key购买 nike

我正在尝试更改一个资源中的属性,并想在另一个资源中使用更新后的值,但更新后的值没有反射(reflect)在另一个资源中。请帮助我

代码

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​​ block 更改您的属性值之前。您需要在代码块周围添加惰性初始化程序。

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

第一个 block 实际上并不需要惰性,但我把它放在那里以防其他地方的值也发生变化。

关于ruby - 如何将值(value)从一种资源传递到 Chef Recipe 中的另一种资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29718425/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com