On 2016-06-27 11:54 AM, Pearl Raj wrote:
Hi, While setting up persistant load balancer configuration in linux
virtul server, I ended up with following two templates.
On the load balancer: In lvs/manifests/ifcfg-lo_lb.erb
DEVICE=eth1:lb
IPADDR=<IP_ADDRESS>
NETMASK=255.255.255.0
ONBOOT=yes
NM_CONTROLLED=no
On the app servers: In lvs/manifests/ifcfg-eth1_lb.erb
DEVICE=lo:lb
IPADDR=<IP_ADDRESS>
NETMASK=255.255.255.255
ONBOOT=yes
...(snip)...
Is it possible to use one common template instead of two with some
conditional statements differentiating load balancer and app server?
Absolutely. There are a couple ways.
Firstly, there's nothing stopping you from setting NM_CONTROLLED=yes ...
so perhaps the obvious solution is to just define a variable that has
either the value "yes" or "no" depending on the server's role and you
fill the value into the template the same way you do with the IP
address. You will need to use this approach to template the device name.
The other option is to conditionally include the line. All you need to
do is define some variable (doesn't matter if it comes from Hiera or is
a local variable inside your class) do something like this in your template:
<% if @is_load_balancer -%>
NM_CONTROLLED=no
<% end -%>
When @is_load_balancer evaluates to true, then the line gets included in
the output. If it evaluates to false, it gets excluded from the output.
Note the use of "-%>" instead of "%>" -- that prevents you from getting
extra blank lines in the final output. Also note the use of "<%"
instead of "<%=".... the "<%" syntax allows you to run any arbitrary
Ruby code you want, whereas "<%=" outputs the value of a variable.
Because "<%" allows you to execute arbitrary Ruby code, you can not only
do conditional logic as shown above, but also iteration and other fun
things, for example:
<% @vhosts.each do |vhost| -%>
<%= vhost %>
<% end -%>
Which would take an array and output each element on its own line.
--
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/57715700.70404%40alter3d.ca.
For more options, visit https://groups.google.com/d/optout.