Jos Backus
2007-Apr-26 23:50 UTC
[PATCH] facter: add interfaces, default_gateway facts on Linux
Quick and dirty: --- lib/facter.rb (revision 203) +++ lib/facter.rb (working copy) @@ -989,6 +989,18 @@ %x{/usr/sbin/scutil --get LocalHostName} end end + Facter.add(:interfaces) do + confine :kernel => :linux + setcode do + %x{/sbin/ifconfig -a -s}.split($/)[1..-1].collect {|line| line.split}.collect {|line| line.first} + end + end + Facter.add(:default_gateway) do + confine :kernel => :linux + setcode do + %x{/bin/netstat -rn}.split($/)[1..-1].collect {|line| line.split}.select {|line| line[0] == ''0.0.0.0''}.collect {|line| line[1]} + end + end Facter.add(:iphostnumber) do confine :kernel => :darwin, :kernelrelease => "R6" setcode do On a related note: how would I go about obtaining facts for a particular interface? We use a combination of VLANs and bonding at work so we have interface names like `eth0'', `bond0'' and `bond0.401''. Is the best practice to create facts such as `mac_address[bond0.401]''? These facts would allow us to verify that a given machine has the proper interface configuration. -- Jos Backus jos at catnook.com
Matthew Flanagan
2007-Apr-27 04:34 UTC
Re: [PATCH] facter: add interfaces, default_gateway facts on Linux
On 4/27/07, Jos Backus <jos@catnook.com> wrote:> Quick and dirty: > > --- lib/facter.rb (revision 203) > +++ lib/facter.rb (working copy) > @@ -989,6 +989,18 @@ > %x{/usr/sbin/scutil --get LocalHostName} > end > end > + Facter.add(:interfaces) do > + confine :kernel => :linux > + setcode do > + %x{/sbin/ifconfig -a -s}.split($/)[1..-1].collect {|line| line.split}.collect {|line| line.first} > + end > + end > + Facter.add(:default_gateway) do > + confine :kernel => :linux > + setcode do > + %x{/bin/netstat -rn}.split($/)[1..-1].collect {|line| line.split}.select {|line| line[0] == ''0.0.0.0''}.collect {|line| line[1]} > + end > + end > Facter.add(:iphostnumber) do > confine :kernel => :darwin, :kernelrelease => "R6" > setcode do > > On a related note: how would I go about obtaining facts for a particular > interface? We use a combination of VLANs and bonding at work so we have > interface names like `eth0'', `bond0'' and `bond0.401''. Is the best practice to > create facts such as `mac_address[bond0.401]''? > > These facts would allow us to verify that a given machine has the proper > interface configuration. > > -- > Jos Backus > jos at catnook.comFacter can only return facts as strings at the moment. I raised the need for more structured facts [1] for interface configs a year ago. There was someone working on this at one point (Eric H? on irc from memory) but nothing ever materialised. [1] http://reductivelabs.com/trac/facter/ticket/6 -- matthew http://wadofstuff.blogspot.com
Jos Backus
2007-Apr-27 15:26 UTC
Re: [PATCH] facter: add interfaces, default_gateway facts on Linux
On Fri, Apr 27, 2007 at 02:34:13PM +1000, Matthew Flanagan wrote: [snip]> Facter can only return facts as strings at the moment. I raised the > need for more structured facts [1] for interface configs a year ago. > There was someone working on this at one point (Eric H? on irc from > memory) but nothing ever materialised. > > [1] http://reductivelabs.com/trac/facter/ticket/6Bummer. It looks like the Puppet interface definition is the problem, which means it needs some design work. I could do the code if the design was known. Thanks, Matthew. -- Jos Backus jos at catnook.com