Hi, I''m currently trying to write a simple function to generate a random password. I have looked at the fqdn_rand.rb script to get things going but unfortunately my ruby skills are very bad. I found the following code snippet that does what I need: begin def random_password(size = 8) chars = ((''a''..''z'').to_a + (''0''..''9'').to_a) - %w(i o 0 1 l 0) (1..size).collect{|a| chars[rand(chars.size)] }.join end puts random_password.inspect end I just can''t get this to work in my custom function: cat ../lib/puppet/parser/functions/rand_pw.rb Puppet::Parser::Functions::newfunction(:rand_pw, :type => :rvalue, :doc => "Returns a random string.") do |args| chars = ((''a''..''z'').to_a + (''0''..''9'').to_a) - %w(i o 0 1 l 0) (1..args[0]).collect{|a| chars[rand(chars.args[0])] }.join end and this is the function call in the manifest: $username2pass = rand_pw(10) The error I get is: err: Could not retrieve catalog from remote server: Error 400 on SERVER: bad value for range at /etc/puppet/modules/production/users/ manifests/params.pp:11 on node Regards, -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Krzysztof Wilczynski
2012-Apr-03 11:36 UTC
[Puppet Users] Re: Custom Function to generate random password
Hi, On Tuesday, 3 April 2012 07:36:06 UTC+1, r0k5t4r wrote:> > Hi, > > I''m currently trying to write a simple function to generate a random > password. I have looked at the fqdn_rand.rb script to get things going > but unfortunately my ruby skills are very bad. >[...] Try this one: https://github.com/kwilczynski/puppet-functions/blob/master/lib/puppet/parser/functions/random_password.rb KW -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/53Dd49kLNDcJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
r0k5t4r
2012-Apr-03 13:01 UTC
[Puppet Users] Re: Custom Function to generate random password
Hi, thanks a lot. Just what I was looking for. Works like a charm. :) Best Regards On 3 Apr., 13:36, Krzysztof Wilczynski <krzysztof.wilczyn...@linux.com> wrote:> Hi, > > On Tuesday, 3 April 2012 07:36:06 UTC+1, r0k5t4r wrote: > > > Hi, > > > I''m currently trying to write a simple function to generate a random > > password. I have looked at the fqdn_rand.rb script to get things going > > but unfortunately my ruby skills are very bad. > > [...] > > Try this one:https://github.com/kwilczynski/puppet-functions/blob/master/lib/puppe... > > KW-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Krzysztof Wilczynski
2012-Apr-03 13:27 UTC
[Puppet Users] Re: Custom Function to generate random password
Hi, I am glad you found it useful. KW On Tuesday, 3 April 2012 14:01:44 UTC+1, r0k5t4r wrote:> > Hi, > > thanks a lot. Just what I was looking for. Works like a charm. :) > > Best Regards > > On 3 Apr., 13:36, Krzysztof Wilczynski > <krzysztof.wilczyn...@linux.com> wrote: > > Hi, > > > > On Tuesday, 3 April 2012 07:36:06 UTC+1, r0k5t4r wrote: > > > > > Hi, > > > > > I''m currently trying to write a simple function to generate a random > > > password. I have looked at the fqdn_rand.rb script to get things going > > > but unfortunately my ruby skills are very bad. > > > > [...] > > > > Try this one: > https://github.com/kwilczynski/puppet-functions/blob/master/lib/puppe... > > > > KW-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/snUP4f6txQcJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.