in Education by
Let's say I have one variable, directory_list, which I define and set in a ruby_block named get_directory_list. Can I use directory_list later on in my recipe, or will the compile/converge processes prevent this? Example: ruby_block "get_file_list" do block do transferred_files = Dir['/some/dir/*'] end end transferred_files.each do |file| file "#{file}" do group "woohoo" user "woohoo" end end Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
For this, you have 2 ways Option1: File resource can also put inside the ruby block for that you can use like this to your example mentioned in the question ruby_block "get_file_list" do block do files = Dir['/some/dir/*'] files.each do |f| t = Chef::Resource::File.new(f) t.owner("woohoo") t.group("woohoo") t.mode("0600") t.action(:create) t.run_context=(rc) t.run_action(:create) end end end Option 2: In this type you can use node.run_state to pass data around. For this let’s see how to pass data with respect to example ruby_block "get_file_list" do block do node.run_state['transferred_files'] = Dir['/some/dir/*'] end end node.run_state['transferred_files'].each do |file| file "#{file}" do group "woohoo" user "woohoo" end end

Related questions

0 votes
    I declare steps that need to be done in order to install wordpress in an array in the beginning of ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Aug 1, 2022 in Education by JackTerrance
0 votes
    In Ruby, Dir.glob("**/*.rb") (for instance) doesn't traverse symlinked directories. Is it ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    This is what I have so far: myArray.map!{ rand(max) } Obviously, however, sometimes the numbers ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 23, 2022 in Education by JackTerrance
0 votes
    This question exist only because of pure curiosity. Not a homework. Find the fastest way to find two ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 20, 2022 in Education by JackTerrance
0 votes
    first..sorry for my poor english and my big noob question..the problem is... I need create a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    As the title suggests, I'm just looking for a way of pressing a button in Shoes without clicking ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    I am trying to do a poc of Jenkins pipeline as code. I am using the Github organization folder plugin to ... descriptions for the jobs Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    My docker-compose file has some running docker files to create my containers. I don't want the docker files ... docker-compose syntax? Select the correct answer from above options...
asked Jan 25, 2022 in Education by JackTerrance
0 votes
    I've been using K8S ConfigMap and Secret to manage our properties. My design is pretty simple, that keeps ... 't been created Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me what are performance tools used in DevOps? Select the correct answer from above options...
asked Jan 9, 2022 in Education by JackTerrance
0 votes
    I am trying to start a local Kubernetes cluster using minikube start and getting the following error. Starting local ... this slow? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I want to migrate my webapp from Amazon EC2 to ECS. I ECS I have to allocate memory and vCPU for the ... needed for the process? Select the correct answer from above options...
asked Jan 25, 2022 in Education by JackTerrance
0 votes
    Could someone tell me how to make a career transition from Test Engineer to DevOps Engineer? Select the correct answer from above options...
asked Jan 6, 2022 in Education by JackTerrance
0 votes
    I am setting up a common standalone-full.xml file for all server environments, and therefore need to have ... is greatly appreciated. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
...