0

I have a code, in that code it contains ruby_block. What are the values generating in that ruby_block, I want use them in out side/in another resource in same recipe file.

Dir.chdir("#{Chef::Config[:file_cache_path]}")
Dir.glob("test-*.msi").each { |file| File.delete(file)}

windows_zipfile "#{Chef::Config[:file_cache_path]}" do
source node['seps_infrastructure']['zip_file']
action :unzip
overwrite true
end

ruby_block 'check_vpn_ip_list' do
block do
node.run_state['msi_file'] = Dir.glob(""test-*.msi"")
node.run_state['ver'] = (node.run_state['msi_file'])[0].split('-    ')[3].chomp(".msi")
end
end
puts  node.run_state['ver']
puts  node.run_state['msi_file']
2

1 Answer 1

0

first, as a rule of thumb, i would advise you to utilize chef resources and not have ruby code outside of such resources (since ruby block outside of chef resource will be executed on compilation phase and not the convergence phase of chef-client run. of course, there are some exceptions to this rule). for instance, place

Dir.chdir("#{Chef::Config[:file_cache_path]}")
Dir.glob("test-*.msi").each { |file| File.delete(file)}

within a ruby_block resource.

relating to your question, you can assign a node attribute within the ruby_block and use the same node attribute when needed. for instance:

ruby_block 'foo' do
  block do
    node.default['files'] = Dir.glob("test-*.msi")
  end
end

execute 'baz' do
  command "echo #{node['files']}"
end
Sign up to request clarification or add additional context in comments.

1 Comment

Not on any other resource.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.