Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (12.7k points)

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

1 Answer

0 votes
by (29.5k points)

What i would do is i would put the file resource inside the the ruby_block which would look something like this

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

Related questions

0 votes
1 answer
asked Jan 17, 2020 in DevOps and Agile by Abhishek_31 (12.7k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...