Search code examples
puppetpuppet-enterprise

How to calculate value in puppet erb file


I'm new to puppet and realy need some help with it:

I have the following value im my application my_app.pp value:

akka_application_cluster_seed_nodes => '"akka.tcp://ActorSystem@host1:2551","akka.tcp://ActorSystem@host2:2551","akka.tcp://ActorSystem@host3:2551"'

Now in my erb file min-nr-of-members value should be calculated by getting the size of akka_application_cluster_seed_nodes array divide by 2 plus 1

 $min-nr-of-members = $akka_application_cluster_seed_nodes.size/2 +1

For example:

  auto-down-unreachable-after = <%= get_param('akka_cluster_auto_down_unreachable_after')%>

and something like this:
      <% $cluster= get_param('akka_cluster_auto_down_unreachable_after') %>
      <% $minNumOfNodes = ($cluster.size / 2)+1 %>

min-nr-of-members = <% $minNumOfNodes %>

Can you please help?


Solution

  • '"akka.tcp://ActorSystem@host1:2551","akka.tcp://ActorSystem@host2:2551","akka.tcp://ActorSystem@host3:2551"'
    

    is not an array in puppet. Use split function to create an array from it :

    $array_nodes = split($akka_application_cluster_seed_nodes, ',')
    

    Next use size function from stdlib to calculate array size in puppet, and calculate desired value:

    $array_size = size($array_nodes)
    

    Then use it in your erb file:

    min-nr-of-members = <%= Integer(@array_size) / 2 + 1 %>