Ask Your Question
1

ruby code in template not working with Puppet 4.x anymore

asked 2017-07-21 17:17:43 -0500

parmtree gravatar image

updated 2017-07-22 05:49:52 -0500

I used following code to generate random orders of LDAP servers in client config file, it won't change the orders in next puppet agent run. However in Puppet v4+, it doesn't seem to work any more, every time when agent runs, it changes the order in the config file. Does anyone know why?

ldap_uri = <%
  server_list = @_ldap_servers.dup
  server_list.size.times do
    server = server_list[rand(server_list.size)] -%>ldaps://<%= server -%>/ <%
    server_list.delete(server)
  end %>

PS: $_ldap_servers is a list value (ex, $_ldap_servers = ['ldap1', 'ldap2', 'ldap3'])

edit retag flag offensive close merge delete

Comments

Kai Burghardt gravatar imageKai Burghardt ( 2017-07-22 05:55:46 -0500 )edit

Thanks for being obssesive compulsive editing my original questions. :) Tried shuffle, seems to do the same thing - keep changing orders. Checked the ruby version on my old puppet server and the new one, both are running same Ruby 2.x.

parmtree gravatar imageparmtree ( 2017-07-22 07:37:36 -0500 )edit

Another major difference is that my Puppet 3 is Rack/Passenger based, my Puppet 4 is Puppetserver 2.7.x.

parmtree gravatar imageparmtree ( 2017-07-22 07:46:14 -0500 )edit

do you want it random per server, but static (given the same input) on the same server? if so, use https://docs.puppet.com/puppet/latest/function.html#fqdnrand You would probably use that external to the template, and pass it in

DarylW gravatar imageDarylW ( 2017-07-24 08:25:16 -0500 )edit

1 Answer

Sort by » oldest newest most voted
2

answered 2017-07-25 04:24:05 -0500

ramindk gravatar image

I think I answered this on the mailing list. fqdn_rotate from stdlib makes this pretty easy to solve.

$_ldap_servers = ['ldap1','ldap2','ldap3']
$whatever = fqdn_rotate(sort($_ldap_servers)

Then add whatever else you need to do.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-07-21 17:17:43 -0500

Seen: 62 times

Last updated: Jul 25