Hi, I''m trying to write a SSH module to learn Hiera. The module is including a Firewall config from the Puppetlabs Firewall module. I''ve made the port configurable using a variable "ssh_server_port". $port = hiera(''ssh_server_port'') firewall { "100 SSHD": proto => ''tcp'', action => ''accept'', dport => $port, } If I do $ssh_server_port = 22 in a Puppet file everything works as expected. If I''m using a YAML file with this: ssh_server_port: 2222 I get the following error message: Parameter dport failed: Munging failed for value 2222 in class dport: can''t convert Fixnum into String It makes sense for the Firewall module to require a String here as it accepts ranges too. With ssh_server_port: ''2222'' in the YAML file everything works as expected. It would be nice for a plain Integer (Fixnum) to work as well when it''s coming from a YAML file. I guess the question boils down to: Is there a way to cast from Fixnum to String? It seems like an inconsistency to me that in Puppet it works quoted and unquoted but not in YAML so I''d like to provide the same syntax for both versions. For now i''ve added a validate_string($port) call. Thanks, Lars -- 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-Mar-01 18:52 UTC
[Puppet Users] Re: Casting Fixnum to String (Hiera/YAML)
Hi Lars, [...]> It would be nice for a plain Integer (Fixnum) to work as well when > it''s coming from a YAML file.When you introduce a numeric value through the manifest, then Puppet will do the right thing during parsing it, but when you introduce Integer or Float from Hiera, then you will get them "as-is" after parsing YAML, meaning as intended types in Ruby, so to speak. And because Ruby is dynamic and uses duck-typing, it simply just work internally to the point when parser is trying to combine both types.> I guess the question boils down to: Is there a way to cast from Fixnum > to String?Yes, look below :)> It seems like an inconsistency to me that in Puppet it works quoted > and unquoted but not in YAML so I''d like to provide the same syntax > for both versions. For now i''ve added a validate_string($port) call.Puppet in most cases treats non-negative Internet and Float as string (unless this behavior differs nowadays). Take a look on this: https://github.com/kwilczynski/puppet-functions/blob/master/lib/puppet/parser/functions/num2str.rb And this: https://github.com/kwilczynski/puppet-functions/blob/master/lib/puppet/parser/functions/type.rb I hope it helps a little :) 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.
Lars Francke
2012-Mar-02 10:59 UTC
Re: [Puppet Users] Re: Casting Fixnum to String (Hiera/YAML)
Hi Krzysztof,>> I guess the question boils down to: Is there a way to cast from Fixnum >> to String? > > Yes, look below :)Excellent!> Take a look on this: > > https://github.com/kwilczynski/puppet-functions/blob/master/lib/puppet/parser/functions/num2str.rb > > And this: > > https://github.com/kwilczynski/puppet-functions/blob/master/lib/puppet/parser/functions/type.rb > > I hope it helps a little :)Yes, thank you very much! This looks like a good addition for puppet-stdlib, no? Thanks for taking the time to answer. Cheers, Lars -- 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.