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
>> 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