Gabriel Filion
2011-Feb-08 02:14 UTC
[Puppet Users] can we choose which inteface defines the $ipaddress fact?
Hi, I''ve run into some bug today with nagios checks that are exported in a client''s puppet setup. The problem is that some host definitions are exported with an internal address (10.x or 192.168.x) even though the servers do have an external IP on another interface. One of those uses a tap inteface to bridge traffic, and another has a virtual interface that is used for a vlan. In all cases, the interface with an internal IP comes up higher in the output of ifconfig, and this makes the fact "ipaddress" take it as its value. Is there a way to force facter to chose a specific interface for the ipaddress value? -- Gabriel Filion -- 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.
Patrick
2011-Feb-08 05:05 UTC
Re: [Puppet Users] can we choose which inteface defines the $ipaddress fact?
On Feb 7, 2011, at 6:14 PM, Gabriel Filion wrote:> Hi, > > I''ve run into some bug today with nagios checks that are exported in a > client''s puppet setup. > > The problem is that some host definitions are exported with an internal > address (10.x or 192.168.x) even though the servers do have an external > IP on another interface. > > One of those uses a tap inteface to bridge traffic, and another has a > virtual interface that is used for a vlan. > > In all cases, the interface with an internal IP comes up higher in the > output of ifconfig, and this makes the fact "ipaddress" take it as its > value. > > Is there a way to force facter to chose a specific interface for the > ipaddress value?Yes and no. Try running "facter | grep ipaddress" on the client. This will give you the names of variables you should be using instead that are listed by interface. -- 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.
Gabriel Filion
2011-Feb-08 19:03 UTC
Re: [Puppet Users] can we choose which inteface defines the $ipaddress fact?
On 11-02-08 12:05 AM, Patrick wrote:> Yes and no. > > Try running "facter | grep ipaddress" on the client. This will give you the names of variables you should be using instead that are listed by interface.hmm, well thanks for confirming this. I''ll have to put some effort on my nagios module to provide for an override for the ip address, then. -- Gabriel Filion -- 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.
Brian
2011-Feb-08 20:19 UTC
[Puppet Users] Re: can we choose which inteface defines the $ipaddress fact?
On Feb 7, 9:14 pm, Gabriel Filion <lelu...@gmail.com> wrote:> In all cases, the interface with an internal IP comes up higher in the > output of ifconfig, and this makes the fact "ipaddress" take it as its > value. > > Is there a way to force facter to chose a specific interface for the > ipaddress value?I feel your pain! I have two facts, ipaddress_public and ipaddress_private, that I defined to work around this. http://polibyte.com/blog/getting_ip_addresses_with_facter All the best, Brian Pitts -- 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.
Patrick
2011-Feb-08 20:30 UTC
Re: [Puppet Users] Re: can we choose which inteface defines the $ipaddress fact?
On Feb 8, 2011, at 12:19 PM, Brian wrote:> On Feb 7, 9:14 pm, Gabriel Filion <lelu...@gmail.com> wrote: >> In all cases, the interface with an internal IP comes up higher in the >> output of ifconfig, and this makes the fact "ipaddress" take it as its >> value. >> >> Is there a way to force facter to chose a specific interface for the >> ipaddress value? > > I feel your pain! I have two facts, ipaddress_public and > ipaddress_private, that I defined to work around this. > > http://polibyte.com/blog/getting_ip_addresses_with_facterThis is really interesting. One change you might want to consider making is to say that a 169.*.*.* ipaddresses doesn''t count as having a valid address. -- 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.
Naresh V
2011-Feb-09 06:01 UTC
Re: [Puppet Users] can we choose which inteface defines the $ipaddress fact?
On 8 February 2011 07:44, Gabriel Filion <lelutin@gmail.com> wrote: [...]> Is there a way to force facter to chose a specific interface for the > ipaddress value?Hi, I was wondering *when* would this part of the ipaddress.rb fact code would be used: --(0)> tail -20 /usr/lib/ruby/site_ruby/1.8/facter/ipaddress.rb Facter.add(:ipaddress, :timeout => 2) do setcode do if hostname = Facter.value(:hostname) # we need Hostname to exist for this to work host = nil if host = Facter::Util::Resolution.exec("host #{hostname}") list = host.chomp.split(/\s/) if defined? list[-1] and list[-1] =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/ list[-1] end else nil end else nil end end end --(naresh.ve@puppet)-(~)-- --(0)> irb -rfacter irb(main):001:0> Facter::Util::Resolution.exec("host puppet.domain.com") => "puppet.directi.com has address a.b.c.d" irb(main):002:0> host = Facter::Util::Resolution.exec("host puppet.domain.com") => "puppet.directi.com has address a.b.c.d" irb(main):003:0> list = host.chomp.split(/\s/) => ["puppet.directi.com", "has", "address", "a.b.c.d"] irb(main):004:0> if defined? list[-1] and list [-1] =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/ irb(main):005:1> list[-1] irb(main):006:1> end => "a.b.c.d" irb(main):007:0> (masked my IP with a.b.c.d) If this part were the default/first piece of code that''d be used to produce the ipaddress fact, setting the right A record for the fqdn should solve the problem? -Naresh -- 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.
Gabriel Filion
2011-Feb-09 14:23 UTC
Re: [Puppet Users] can we choose which inteface defines the $ipaddress fact?
On 11-02-09 01:01 AM, Naresh V wrote:> Facter.add(:ipaddress, :timeout => 2) do > setcode do > if hostname = Facter.value(:hostname) > # we need Hostname to exist for this to work > host = nil > if host = Facter::Util::Resolution.exec("host #{hostname}") > list = host.chomp.split(/\s/) > if defined? list[-1] and > list[-1] =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/ > list[-1] > end > else > nil > end > else > nil > end > end > end> If this part were the default/first piece of code that''d be used to > produce the ipaddress fact, setting the right A record for the fqdn > should solve the problem?hmm this fact looks like it won''t work for any host that doesn''t resolve, which would be problematic for something like a test setup with virtual machines. -- Gabriel Filion -- 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.
Klaus Ethgen
2011-Feb-09 16:41 UTC
Re: [Puppet Users] Re: can we choose which inteface defines the $ipaddress fact?
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 Hmm.. I had similar problem without solving it the elegant way until now. But how about the following algorithm: - - Check which interface has the default routing - - If no default routing take the first one Regards Klaus - -- Klaus Ethgen http://www.ethgen.ch/ pub 2048R/D1A4EDE5 2000-02-26 Klaus Ethgen <Klaus@Ethgen.de> Fingerprint: D7 67 71 C4 99 A6 D4 FE EA 40 30 57 3C 88 26 2B -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iQEVAwUBTVLDoZ+OKpjRpO3lAQo4Cgf/Z59ICBNqseZbCSi/AZMuEL3DlrT7xSiN 7nLLEV8beJTmBg9ueAoJhu5gDvvWzJf8rUq2yIlW1TW7sTFBAem+hWSnQbE4CBRc X71HW1asuuK6OipzjEauJKz6o3zJ3hzpQ8EY+gEW9O+5N7Ud13XJ66kOTeukpdRd USncCYHXszpjrM2GAEEegh+JXGr7Jd9h+VvKIuaa1vlKzfvwyNFZAfrImP6ZXbcc RxkUAVpvi+QHWqwYZh2a5yqYcNkbcmjy43PW7km9QtHTWgHefpeuNzzcKO2aJrAr 5tBwk7lHVAclWydwplCdLIZK0Nq2BvUXOfL/SCSoFB/7DcMNtzg63A==tOoD -----END PGP SIGNATURE----- -- 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.
Daniel Pittman
2011-Feb-14 03:02 UTC
Re: [Puppet Users] Re: can we choose which inteface defines the $ipaddress fact?
On Wed, Feb 9, 2011 at 08:41, Klaus Ethgen <Klaus+puppet@ethgen.de> wrote: Sorry for jumping in late to this discussion, but: To answer the original query, "is it possible to change which IP address is used?": No, it is not possible, because this is a daft fact that *claims* to deliver something that is, in fact, not an actual bit of information. So, don''t expect significant work to "improve" the ipaddress fact, which is a sow''s ear, and unlikely to ever become a silk purse. As to...> Hmm.. I had similar problem without solving it the elegant way until > now. > > But how about the following algorithm: > - - Check which interface has the default routing > - - If no default routing take the first one...the proposed algorithm fails entirely on machines with more than one "default" route, or without a default route at all, because it will pick the wrong answer for a subset of systems. It /might/ be a smaller subset of systems but, honestly, I doubt it would be. The only place it really works is a single-address system with a single NIC, and those usually don''t have an extra address to fool the tool anyhow. The correct answer is that if you believe that your machine has a primary IP address of some description then, indeed, you need to supply a custom fact that determines whatever it is by the rules of your own network. Historically, I actually found it much more valuable to use this sort of construction: # The syntax is from memory, and I always get generate wrong, but you should get the idea. $main_ip = generate(''/usr/local/bin/get-ip-from-dns-for'', $fqdn) That would run on the master and consult an authoritative database to get the identity of a machine by name, which is generally what is actually desired in this particular fact. Also notable is the fact that using appropriate convention allows you to have *multiple* identities for machines with multiple addresses, something that is almost always a true situation for such hosts. Regards, Daniel -- ⎋ Puppet Labs Developer – http://puppetlabs.com ✉ Daniel Pittman <daniel@puppetlabs.com> ✆ Contact me via gtalk, email, or phone: +1 (877) 575-9775 ♲ Made with 100 percent post-consumer electrons -- 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.