julien cosmao
2012-Jul-17 13:30 UTC
[Puppet Users] How to override $::operatingsystem fact
Hi, I want to introduce "Proxmox" as new value in $::operatingsystem. "Proxmox" is based on Debian, so the normal value is currently "Debian". To change that, I just write a custom fact based on the facter fact "operatingsystem" Facter.add(:operatingsystem) do> ... > setcode do > ... > elsif FileTest.exists?("/usr/bin/pveversion") > "Proxmox"This method doesn''t override the original fact. I''ve also tried to set $::operatingsystem = "Proxmox" directly in my node. What''s the best way to do override an existing fact ? Regards, Julien -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/32I89ua-O8wJ. 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.
julien cosmao
2012-Jul-17 14:44 UTC
[Puppet Users] Re: How to override $::operatingsystem fact
I tried this method too: http://www.puppetcookbook.com/posts/override-a-facter-fact.html It works with puppet 2.7, but not with 2.6.2 [16:41:15 #168 root@:~$ ] FACTER_operatingsystem=plop puppet -e ''notify {> "We are running on $::operatingsystem": }'' > notice: We are running on Debian > notice: /Stage[main]//Notify[We are running on Debian]/message: defined > ''message'' as ''We are running on Debian'' > [16:41:32 #169 root@:~$ ] puppetd --version > 2.6.2 > [16:41:35 #170 root@:~$ ] puppet agent --version > 2.6.2Le mardi 17 juillet 2012 15:30:15 UTC+2, julien cosmao a écrit :> > Hi, > > I want to add "Proxmox" as new value in $::operatingsystem. > "Proxmox" is based on Debian, so the normal value is currently "Debian". > > To change that, I just write a custom fact based on the facter fact > "operatingsystem" > > Facter.add(:operatingsystem) do >> ... >> setcode do >> ... >> elsif FileTest.exists?("/usr/bin/pveversion") >> "Proxmox" > > > This method doesn''t override the original fact. > > I''ve also tried to set $::operatingsystem = "Proxmox" directly in my node. > > What''s the best way to do override an existing fact ? > > Regards, > > Julien > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/Iwk2fRGZe-sJ. 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.
Hailee Kenney
2012-Jul-17 17:34 UTC
[Puppet Users] Re: How to override $::operatingsystem fact
Hi Julien, When writing custom facts, you can specify precedence by setting a weight for your fact resolution. By default, the weight of a fact resolution is the number of confines it has. Since your custom fact resolution has no confine statements, and the default operatingsystem resolutions have one, your custom fact will not take precedence. There is a good explanation for how to set the weight of your custom fact here: http://docs.puppetlabs.com/guides/custom_facts.html If you''re sure you''d always like your custom fact to take precedence, you can set the weight to something like 50 or 100. Hope this helps! Hailee -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/OVUNvZOHn-wJ. 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.
Garrett Honeycutt
2012-Jul-18 01:55 UTC
Re: [Puppet Users] How to override $::operatingsystem fact
On 7/17/12 11:30 PM, julien cosmao wrote:> Hi, > > I want to introduce "Proxmox" as new value in $::operatingsystem. > "Proxmox" is based on Debian, so the normal value is currently "Debian". > > To change that, I just write a custom fact based on the facter fact > "operatingsystem" > > Facter.add(:operatingsystem) do > ... > setcode do > ... > elsif FileTest.exists?("/usr/bin/pveversion") > "Proxmox" > > > This method doesn''t override the original fact. > > I''ve also tried to set $::operatingsystem = "Proxmox" directly in my node. > > What''s the best way to do override an existing fact ? > > Regards, > > JulienCreated feature request[1] #15579 to add Proxmox support to facter. [1] - http://projects.puppetlabs.com/issues/15579 -g -- Garrett Honeycutt 206.414.8658 http://puppetlabs.com -- 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.
j.cosmao@gmail.com
2012-Jul-18 09:38 UTC
Re: [Puppet Users] How to override $::operatingsystem fact
Hi, Thanks ! Hailee, your solution works great. Very usefull for me. 2012/7/18 Garrett Honeycutt <garrett@puppetlabs.com>> On 7/17/12 11:30 PM, julien cosmao wrote: > > Hi, > > > > I want to introduce "Proxmox" as new value in $::operatingsystem. > > "Proxmox" is based on Debian, so the normal value is currently "Debian". > > > > To change that, I just write a custom fact based on the facter fact > > "operatingsystem" > > > > Facter.add(:operatingsystem) do > > ... > > setcode do > > ... > > elsif FileTest.exists?("/usr/bin/pveversion") > > "Proxmox" > > > > > > This method doesn''t override the original fact. > > > > I''ve also tried to set $::operatingsystem = "Proxmox" directly in my > node. > > > > What''s the best way to do override an existing fact ? > > > > Regards, > > > > Julien > > Created feature request[1] #15579 to add Proxmox support to facter. > > [1] - http://projects.puppetlabs.com/issues/15579 > > -g > > -- > Garrett Honeycutt > > 206.414.8658 > http://puppetlabs.com > > > -- > 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. > >-- Julien COSMAO tel: +33(0)6 32 34 99 87 Mail : j.cosmao@gmail.com -- 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.
Heiko Finzel
2013-Mar-19 22:28 UTC
[Puppet Users] Re: How to override $::operatingsystem fact
Hi I''m having a similar issue. I found the solution Hailee posted here in the official documentation and gave it a try. The weight seems to work great as long as it concerns my own facts. But as it seems it won''t work for build in types. In my special case I want to override the hostname fact, but I also tried operationsystem, as mentioned here. I configured weights from -100 to 9999999... just to be sure ;) Julien wrote , it worked great, so am I doing something wrong? I''m running puppet 3.1 (master and client) A basic testing rule I use for debugging purpose is: exportfile = ''/etc/facter_export'' if File.exists?(exportfile) then File.open(exportfile, ''r'').each do |line| unless line =~ /^\s*#/ then tokens = line.split(''='') Facter.add(tokens[0].strip) do has_weight 100 setcode do tokens[1].strip end end end end end This way it is easy to try overriding build in facts as well as self-written ones. -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Heiko Finzel
2013-Mar-23 18:42 UTC
[Puppet Users] Re: How to override $::operatingsystem fact
EDIT: In fact it does work. I found out, because I still had some keys (e.g. hostname) in my debugging config. And these values were used by puppet correctly. However a local "facter -p" won''t show these values. In this case the original hostname will be used. -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Jakov Sosic
2013-Mar-24 18:10 UTC
Re: [Puppet Users] Re: How to override $::operatingsystem fact
On 03/23/2013 07:42 PM, Heiko Finzel wrote:> EDIT: In fact it does work. > I found out, because I still had some keys (e.g. hostname) in my > debugging config. And these values were used by puppet correctly. > However a local "facter -p" won''t show these values. In this case the > original hostname will be used.That is surely a bug?! -- Jakov Sosic www.srce.unizg.hr -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Just for the record, this is the code I''m using: Facter.add(:operatingsystem) do> confine :kernel => [ ''Linux'' ] > has_weight 100 > setcode do > if FileTest.exists?("/usr/bin/pveversion") then > "Proxmox" > end > end > end > > Facter.add(:operatingsystemrelease) do > confine :kernel => [ ''Linux'' ] > has_weight 100 > setcode do > if FileTest.exists?("/usr/bin/pveversion") then > Facter::Util::Resolution.exec("/usr/bin/pveversion") > end > end > end > >On Tuesday, July 17, 2012 9:30:15 AM UTC-4, julien cosmao wrote:> > Hi, > > I want to introduce "Proxmox" as new value in $::operatingsystem. > "Proxmox" is based on Debian, so the normal value is currently "Debian". > > To change that, I just write a custom fact based on the facter fact > "operatingsystem" > > Facter.add(:operatingsystem) do >> ... >> setcode do >> ... >> elsif FileTest.exists?("/usr/bin/pveversion") >> "Proxmox" > > > This method doesn''t override the original fact. > > I''ve also tried to set $::operatingsystem = "Proxmox" directly in my node. > > What''s the best way to do override an existing fact ? > > Regards, > > Julien > >-- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.