On 21.11.2013 13:32, cko wrote:
> Hi,
> 
> I'm currently trying to solve the following problem:
> 
> I wrote a module that matches the "$ipaddress" fact for certain IP
> subnets (like 20.20.2... or 30.30.2..). Depending on the subnet, the
> variable $proxy-server changes.
> 
> The problem is, that some of our physical machines have a random number
> of interfaces connected to many different subnets. In some cases the
> $ipadddress fact returns the correct subnet, lets call it "production
> server lan" and some don't.
> 
> Is there any way to make puppet check every available NIC for a specific
> subnet/ regex? Something like this:
> 
> if $ipaddress_eth*** =~ /^20\.20\.\..*$/ {
>    $proxy-server = foo
> }
> .
> 
> -- 

I'd recommend to write a custom fact that returns your "production
server lan" ipaddress first and then check only that fact against your
regular expression. The custom fact may look like this:


     require 'ipaddr'
     require 'facter/util/ip'

     Facter.add(:ipaddress_production) do
       setcode do
         production_networks = [
           IPAddr.new('20.20.2.0/24'),
           IPAddr.new('30.30.2.0/24')
         ]
         production_ip = nil

         Facter::Util::IP.get_interfaces.each do |interface|
           ip = Facter::Util::IP.get_interface_value(interface, 'ipaddress')
           if production_networks.any? { |network| network.include? ip }
             production_ip = ip
           end
         end
         production_ip
       end
     end

-Stefan

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/529EEEB6.8090601%40taunusstein.net.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to