I wanted to create the loop using 'each' but I couldn't. When I looked at the examples using 'each', array was always used. Is there a solution using while or for?
while $i <= do
file "/home/user/files/file_#{i}" do
owner 'root'
group 'root'
mode '0755'
action :create
end
$i =1
end
I want it to look like this
file_1 file_2 file_3 ...
CodePudding user response:
You can use times
or range
methods instead of while
.
Example using range:
(1..5).each do |i|
file "/home/user/files/file_#{i}" do
owner 'root'
group 'root'
mode '0755'
action :create
end
end
Here I'm using range of (1..5)
, which will create file_1
to file_5
. You can change it to the numbers with which the files should be created.