Ask Your Question

How to stop Puppet/Facter treating value as a number

asked 2013-05-28 10:23:58 -0500

asdf5 gravatar image

updated 2013-05-29 01:35:37 -0500

I'm having trouble with some kind of automatic conversion occurring when I echo facts into a file. I've got a custom fact defined as follows:

require 'facter'
ports = Facter::Util::Resolution.exec("ibstat -p")
unless ports.nil? or ports.empty?
  ports.each_with_index do |port,index|
    Facter.add("infiniband_port#{index}") do
      setcode { port.to_s }

Looking at Facter I can see the values are set correctly:

infiniband_port0 => 0x0008f1040397064d
infiniband_port1 => 0x0008f1040397064e

Unfortunately they appear to be treated as numbers by Puppet. I see errors in the log on applying the configuration:

err: Failed to apply catalog: Parameter content ...
edit retag flag offensive close merge delete


can you post your manifest in which you are accessing the fact as well?

Stefan gravatar imageStefan ( 2013-05-28 16:43:13 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2013-05-30 22:18:25 -0500

jgoldschrafe gravatar image

updated 2013-05-30 22:18:48 -0500

This smells like a YAML serialization/deserialization issue. If you check out the YAML standard, it's supposed to automagically handle conversion of hexadecimal values into numeric types. I'm suspecting that Facter is serializing the value unquoted into YAML, and when it's being deserialized it's being handled as a number.

Can you post the output of facter --puppet --yaml from your node?

edit flag offensive delete link more


Run w/ and w/o index: infiniband_with_index_0: "0x0008f104039706b9\n" => OK infiniband_with_index_1: 0x0008f104039706ba => FAIL: 2516799356077754 in file infiniband_without_index: "0x0008f104039706b9\n" => OK It was trailing newline causing weirdness - how to stop conversions though?

asdf5 gravatar imageasdf5 ( 2013-05-31 07:05:20 -0500 )edit

Wow, formatting all screwed up in my comment - after all the effort to keep it within character count too! Thanks, it appears that it was the trailing newline that caused ...(more)

asdf5 gravatar imageasdf5 ( 2013-05-31 07:07:23 -0500 )edit

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


Asked: 2013-05-28 10:23:58 -0500

Seen: 146 times

Last updated: May 30 '13