My custom fact is overriding another fact's value

36 views
Skip to first unread message

Matthew Burgess

unread,
May 1, 2014, 8:07:29 AM5/1/14
to puppet...@googlegroups.com
Hi all,

This, to me, is really bizarre.  Here's my code:

Facter.add("hostname_app") do
    setcode do
        hostname_app = Facter.value(:hostname)
        hostname_app[5] = 'a'
        hostname_app
    end
end

Basically, our servers have 2 network cards, and we need to set up DNS for both of its IP addresses.  eth0 & the server's hostname is its 'management' name, and eth1 is the server's 'application'/business network.

The management hostname and application hostname only differ by one letter, which is what the above code is changing.

Now, when this runs, the hostname_app fact is set correctly, but the default hostname fact is also changed similarly!  How on earth is that happening?

I've confirmed that a normal 'facter' run has the correct hostname set, and removing this custom fact also keeps the hostname fact correct under a 'facter -p' run.  However, with this fact in place a 'facter -p' run shows the incorrect hostname fact!

Thanks,

Matt.

pho...@gmail.com

unread,
May 1, 2014, 11:47:37 AM5/1/14
to puppet...@googlegroups.com
I too get this on Facter 2.x and ruby 2.1.x. It seems to be returning the value as a reference instead of a copy. If you make an explicit copy of the variable using something like Facter.value(:whatever).lstrip (the lstrip produces a copy of the string) it seems to work fine. It might be worth opening a jira ticket for this if you can't find out, as this seems really... wrong.

Matthew Burgess

unread,
May 1, 2014, 12:14:24 PM5/1/14
to puppet...@googlegroups.com
Hi there,

Yes, that was exactly what was going on, as pointed out to me by a colleague about 5 minutes after I publically humiliated myself :-)  I just did a "String.new(Facter.value(:hostname))" instead.  I'm not sure it's a bug; probably just Ruby doing a shallow copy.

Thanks!

Matt


--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/366a2f50-8654-4a9e-b227-e10ed12beaa6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages