# How do I access the value of "puppetserver" from Ruby script?

I need to set a custom fact, based on the IP of the Puppet Server that is visible from both the Puppet server and client. From within a manifest that is common to both sides I can use the value $puppetserver. However, I need to access this same variable from one of my Ruby scripts/functions. I understand that it is in base::params. I need to retrieve this IP address so I can pass it to another Ruby script/function that will set my custom fact. I've tried accessing the value using Facter.value(:puppetserver) and Facter.value('puppetserver'), but both methods appear to return nil, so I'm guessing I have a scope problem and I don't know enough about either Ruby or Puppet to figure out the right syntax. Thanks, Ron edit retag close merge delete ## 1 Answer Sort by » oldest newest most voted Hi Ron, I've never tried it, but according to this documentation, it appears that the lookupvar function will do what you want: https://docs.puppetlabs.com/guides/custom_functions.html#using-facts-and-variables I suppose the other option would be to create a file resource that looks something like this to write an external fact on each agent: file { '/etc/puppetlabs/facter/facts.d/puppetserver.txt': ensure => file, owner => 'root', group => 'root', mode => '0644', content => "puppetserver=${::puppetserver}\n"
}


It will take one Puppet run for the external fact to be created, and then on the next Puppet run, the agent will present the puppetserver=A.B.C.D fact back to the master.

Please post back here if you have further questions, if it doesn't work for some reason, or if I've misunderstood what you're trying to do.

more