English 中文(简体)
Chef模板和如何在废墟中做 lo
原标题:Chef templates and how to do a for loop in ruby

我是一帆风顺和che子的新鲜事。 我正试图制造一个 n子。 根据核心数量编织文件。

for i in <%= node["cpu"]["total"]%>
upstream frontends {
        server 127.0.0.1:805x;
    }

end

因此,如果档案中有4个核心是:

upstream frontends {
            server 127.0.0.1:8051;
            server 127.0.0.1:8052;
            server 127.0.0.1:8053;
            server 127.0.0.1:8054;
        }
最佳回答

<>Recipe

template "/etc/nginx/sites-available/my-site.conf" do
  variables :frontends_count => node["cpu"]["total"]
end

<><>Template>

upstream frontends {
<% @frontends_count.times do |i| %>
  server 127.0.0.1:805<%= i + 1 %>;
<% end %>
}
问题回答

我不熟悉主任,因为我是Puppet用户。 总的来说,我要通过:

n.times { |i| puts "server 127.0.0.1:805#{i+1}" }

产出:

server 127.0.0.1:8051
server 127.0.0.1:8052
server 127.0.0.1:8053
server 127.0.0.1:8054

显然,你必须用<代码>n替换node[“cpu”][“ Total”][(我假设,s an integer)并使用puts以外的东西,但这应当由你开始。 我猜测这项工作应在主任进行:

upstream frontends {
<% node["cpu"]["total"].times do |i| -%>
  <%= "server 127.0.0.1:805#{i+1}" %>
<% end -%>
}

下面是说明的例子:

库克群岛:

template "/opt/auth/users.xml" do
 ...
 variables(
   :users => auth_users
 )
end

模板:

<% @users.each do |u| %>
  <user username="<%= u[ username ] %>" password="<%= u[ password ] %>" roles="<%= u[ roles ] if u[ roles ] %>" groups="<%= u[ groups ] if u[ groups ] %>" />
<% end %>




相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签