Balasekhar Nelli
Balasekhar Nelli

Reputation: 1295

How to put cookbook_file resource in for loop?

I am able to add a single file from the Chef cookbook:

cookbook_file '/tmp/File1' do
  source 'default/File1'
  owner   'jenkins'
  group  'jenkins'
  mode   '0755'
end

How can I add File1, File2, File3 using a for loop? I went through chef docs, it is helpless and confusing.

Upvotes: 2

Views: 3384

Answers (1)

StephenKing
StephenKing

Reputation: 37580

That's where you can just use Ruby code (and probably, that's the reason why chef docs don't cover that so much):

['File1', 'File2', 'File3'].each do |file|
  cookbook_file "/tmp/#{file}" do
    source "default/#{file}"
    owner 'jenkins'
    group 'jenkins'
    mode '0755'
  end
end

Upvotes: 5

Related Questions