The cause for your issues is that there's code before the setcode do line, which will cause issues under Facter 4. Having code before setcode do was a bad coding practice but didn't break things in Facter 3. In Facter 4, it does break things.
If you move the hostname=Facter.value(:networking)['hostname'] statement to below setcode do, everything should be fine. Kind regards, Kevin On Thursday, January 20, 2022 at 7:09:34 PM UTC+1 [email protected] wrote: > Upgrade from facter 3.11.14 to 4.2.5 (puppet-agent 5 to 7) broke some of > our custom facts, that use other (custom) facts. > Managed to find the smallest examples of two custom facts that reproduce > the problem. > > First fact, that uses a core fact: > > Facter.add(:my_fact) do > hostname=Facter.value(:networking)['hostname'] > setcode do > hostname > end > end > > Second fact, that uses the first fact: > > my_fact = Facter.value(:my_fact) > Facter.add(:my_new_fact) do > setcode do > my_fact > end > end > > The first fact works, it's the second one that stops working with > puppet7/facter4. > > puppet5/facter3: > amvdi-it133:~# facter -p my_fact my_new_fact > my_fact => amvdi-it133 > my_new_fact => amvdi-it133 > > puppet7/facter4: > mvdi-it133:~# facter -p my_fact my_new_fact > my_fact => amvdi-it133 > my_new_fact => > > Seems to have to do with calling Facter.vaiue in the first fact. > This still does not work: > > Facter.add(:my_fact) do > unused=Facter.value(:networking)['hostname'] > hostname="testing" > setcode do > ... > > But this does: > > Facter.add(:my_fact) do > hostname="testing" > setcode do > ... > > # facter -p my_fact my_new_fact > my_fact => testing > my_new_fact => testing > > Also found that it works if I change the second fact to do the > Facter.value inside the setcode block: > > Facter.add(:my_new_fact) do > setcode do > my_fact = Facter.value(:my_fact) > my_fact > end > end > > Learning this I went back to the first fact and changed it to do the > Facter.value inside the setcode block too like this: > > Facter.add(:my_fact) do > setcode do > hostname=Facter.value(:networking)['hostname'] > hostname > end > end > > That also makes it work regardless of where I do Facter.value in the > second fact. > > I'm at a loss as to what the fact is going on here. Is it a bug? Or is > there a reasonable explanation for it? (I'm a complete Ruby noob, ) > > Regards, > Mark. > -- 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/187eda21-5319-42d9-9e82-a820e05a3670n%40googlegroups.com.
