Puppet template for elasticsearch.yml.erb

72 views
Skip to first unread message

miki

unread,
Aug 30, 2015, 4:09:15 PM8/30/15
to Puppet Users
Hi All,

I am new to puppet template and need your help to update the different cluster name to elasticsearch.erb based on the environments (QA,staging,prod)

init.pp


elasticsearch.yml.erb:

node.name: <%= fqdn %>
network.bind_host: <%= @ipaddress %>
network.publish_host: <%= @ipaddress %>
network.host: <%= @ipaddress %>
cluster name: 

is if statement can do this ? like clustername : <%if fqdn == $qa then elastic-qa-cluster?

Appreciate all your help

Rich Burroughs

unread,
Aug 30, 2015, 4:27:12 PM8/30/15
to puppet...@googlegroups.com
You can do if statements in ERB templates. I've never tried to do exactly what you're doing though and I'm not sure if that's the right syntax.

But I think the way people usually would deal with this sort of thing is with Hiera. Are you using it? You could set a custom fact on your hosts that would tell whether they are QA, staging or Prod. And then have those different values in the Hiera data.

You will probably run into more environment specific data like this and Hiera is a good way to handle it.


Rich

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/42482304-87ef-4439-8a74-e93660d02a70%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jcbollinger

unread,
Aug 31, 2015, 9:21:29 AM8/31/15
to Puppet Users
It's not clear what the "this" is that you want to do.  The fragment you posted is not valid ERB, and it is problematic.  The key to writing ERB templates is to recognize that what you are actually writing is ordinary Ruby code, but presented inside-out:
  • Each span of text outside a scriptlet (<%[=]...%>) can be thought of as being a string argument to a 'print' call.
  • Each expression scriptlet (<%= ... %>) can be thought of as providing a 'print' argument as a Ruby expression (the value of the expression within is printed to the output)
  • Each command scriptlet <% ... %> provides ordinary Ruby code to appear between the 'print' statements implied by the other template elements; the value produced by executing that code is not emitted into the template output.
Template output can certainly be conditional.  Here are two ways to do it:

Using an expression scriptlet:

cluster.name: <%= (fqdn == @qa) ? 'elastic-qa-cluster' : 'other-cluster' %>


Using command scriptlets:

cluster.name: <% if fqdn == @qa { %>elastic-qa-cluster<% } else { %>other-cluster<% }%>


John

Reply all
Reply to author
Forward
0 new messages