I''m trying to create a custom fact. The following code works fine if puppetd runs as a daemon but not from the command line. In other words if this runs on server5 as a daemon, the return is correct, "confidential." But if I run "puppetd -t" from the command line "normal" is returned. I don''t really know ruby so I''m not confident about the code or using the facter/setcode method. Anything I''m doing wrong or is this a puppet/facter bug? I''m using puppetd 0.24.5 and facter 1.5.1. Thanks, Kent -------------------------------------------------------------------------------------------- Facter.add("security_level") do def sec_level() # grab hostname require "socket" hostname = Socket.gethostname # check if hostname matches and designate security level if hostname =~ /(server2|server5|server28)/ level = ''confidential'' else level = ''normal'' end return level end setcode do sec_level end end ----------------------------------------------------------------------------------------- --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
I worked up http://reductivelabs.com/trac/puppet/wiki/Recipes/HostgroupFact to do a similar task. It may be useful to you. -- Mike Renfro / R&D Engineer, Center for Manufacturing Research 931 372-3601 / Tennessee Technological University -----Original Message----- From: Kenton Brede <kbrede@gmail.com> Date: Thursday, Sep 11, 2008 11:27 am Subject: [Puppet Users] custom fact help To: puppet-users@googlegroups.comReply-to: puppet-users@googlegroups.com>I''m trying to create a custom fact. The following code works fine if puppetd runs as a daemon but not from the command line. In other words if this runs on server5 as a daemon, the return is correct, "confidential." But if I run "puppetd -t" >from the command line "normal" is returned. > >I don''t really know ruby so I''m not confident about the code or using the facter/setcode >method. Anything I''m doing wrong or is this a puppet/facter bug? > >I''m using puppetd 0.24.5 and facter 1.5.1. > >Thanks, >Kent > >-------------------------------------------------------------------------------------------- Facter.add("security_level") do > def sec_level() > # grab hostname > require "socket" > hostname = Socket.gethostname > > # check if hostname matches and designate security level > if hostname =~ /(server2|server5|server28)/ > level = ''confidential'' > else > level = ''normal'' > end > return level > end > > setcode do > sec_level > end > >end >----------------------------------------------------------------------------------------- > >> >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---
Follow up on this: My code was fine. Somehow the "level" variable I was using got stuck on "normal." That is, when I ran "puppetd -t." Even if I removed "level = normal" from the manifest, just leaving "level = confidential," "normal" was returned. When puppetd ran as a daemon, the correct variable was returned. The fix was to remove "/var/lib/puppet/yaml/facts/puppet.example.com.yaml." Kent 2008/9/11 Kenton Brede <kbrede@gmail.com>:> I''m trying to create a custom fact. The following code works fine if puppetd > runs as a daemon but not from the command line. In other words if this runs > on server5 as a daemon, the return is correct, "confidential." But if > I run "puppetd -t" > from the command line "normal" is returned. > > I don''t really know ruby so I''m not confident about the code or using > the facter/setcode > method. Anything I''m doing wrong or is this a puppet/facter bug? > > I''m using puppetd 0.24.5 and facter 1.5.1. > > Thanks, > Kent > > -------------------------------------------------------------------------------------------- > Facter.add("security_level") do > def sec_level() > # grab hostname > require "socket" > hostname = Socket.gethostname > > # check if hostname matches and designate security level > if hostname =~ /(server2|server5|server28)/ > level = ''confidential'' > else > level = ''normal'' > end > return level > end > > setcode do > sec_level > end > > end > ----------------------------------------------------------------------------------------- >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---