Igor Zilberman
Igor Zilberman

Reputation: 1208

Chef - repeat block of text in template x times

Is there any way to repeat same text block in template X times? For example, I need to generate template with hosts names and a block of text.

Host1
A lot of text
.
.
HostX
A lot of text

Upvotes: 0

Views: 92

Answers (1)

coderanger
coderanger

Reputation: 54267

Use an each loop in your template:

<%- @hosts.each_with_index do |host, n| -%>
Host<%= n %>
A lot of text involving <%= host %>
etc
etc
<%- end -%>

You can use any normal Ruby flow control stuffs in Erb templates.

Upvotes: 2

Related Questions