[英]Using global variables in chef ruby
Is it possible to define some variable as global in a chef recipe.Like I am declaring & changing a var in a chef resource and later i want to use this changed value in the recipe code. 是否有可能在厨师食谱中将某些变量定义为全局变量。就像我在厨师资源中声明和更改var一样,后来我想在食谱代码中使用此更改的值。
version=""
ruby 'extract_module' do
#cwd ::File.dirname(C:\\chef\\cache)
code <<-EOH
require 'win32/registry'
Win32::Registry::HKEY_LOCAL_MACHINE.open(
'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall') do |reg|
reg.each_key do |key|
k = reg.open(key)
app = k["DisplayName"] rescue nil
if app == "Qlik Sense 3.2"
version = k["DisplayVersion"] rescue nil
puts version
end
end
end
EOH
end
puts "#{version}"
This variable is not printing outside the ruby resource. 此变量不在ruby资源外部打印。 Can we do something like python, declare with global keyword & modify the value.
我们可以做类似python的事情,用global关键字声明并修改值。 Any similar here?
这里有相似之处吗?
The ruby
resource doesn't run in the same process, it runs ruby -E
as a subprocess. ruby
资源不在同一进程中运行,而是将ruby -E
作为子进程运行。 What you want is a ruby_block
resource, which is unrelated. 您需要的是一个不相关的
ruby_block
资源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.