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 On 1 May 2014 16:47, <[email protected]> wrote: > > > On Thursday, May 1, 2014 6:07:29 AM UTC-6, Matthew Burgess wrote: >> >> 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. >> > > > 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. > > -- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/puppet-users/366a2f50-8654-4a9e-b227-e10ed12beaa6%40googlegroups.com<https://groups.google.com/d/msgid/puppet-users/366a2f50-8654-4a9e-b227-e10ed12beaa6%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CAKUTv3%2B8CumT%2B1BsJNp1OMj%2Bf2BEKFz6Bg3UuWzhUQSFinzO8g%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
