Not sure if this would help you, but:
I needed to generate a config file where some value
(netbackup_media_server) depended on the ip of the client (ipaddress
fact), so I did the following inside the template:
# MANAGED BY PUPPET
<%
table="
10.212.3.0/24 nbmedia2-503.example.com 10.212.3.70
10.212.5.0/24 nbmedia2-998.example.com 10.212.5.60
10.212.12.0/24 nbmedia2-512.example.com 10.212.12.66
192.168.63.0/24 nbmedia2-1000.example.com 192.168.1.67
192.168.2.0/26 nbmedia2-2.example.com 192.168.2.22
192.168.2.128/25 nbmedia2-22.example.com
192.168.2.134
"
require 'ipaddr'
#netbackup_media_servers={}
netbackup_media_server=""
table.split(/\n/).each do | line |
line=line.strip
if line
#puts line
net,name,ip=line.split(/\s+/).map{|x| x.strip}
#print net,name,ip
if ! net.nil?
#netbackup_media_servers[net]=[name,ip]
net1 = IPAddr.new(net)
if net1.include?(IPAddr.new(ipaddress))
netbackup_media_server = name
break
end
end
end
end
%>
SERVER = <%= netbackup_master_server %>
SERVER = <%= netbackup_media_server %>
CLIENT_NAME = <%= fqdn %>
SERVER_SENDS_MAIL = YES
CLIENT_READ_TIMEOUT = 20000
CLIENT_CONNECT_TIMEOUT = 3600
LOCKED_FILE_ACTION = SKIP
ALLOW_NON_RESERVED_PORTS = YES
On Thu, Jan 27, 2011 at 2:36 PM, Nick Moffitt <[email protected]> wrote:
> I have a few settings that change based on the network that a system is
> in, and I have a heterogeneous collection of networks (a few /24s, some
> /25s, a /29 and a couple /27s, and hey look a /16 in rfc1918 space
> and...). So I can't do simple regex matches on dotted-quad IP notation
> and expect to get a complete story.
>
> What I'd like is something like, I dunno...
>
> $nameserver = $::ipaddress ? {
> cidr('172.242.0.0/16') => '172.242.111.222',
> cidr('192.168.55.0/25') => '192.168.55.5',
> cidr('192.168.55.128/25') => '192.168.55.205',
> ...
> }
>
> Or really any way to determine whether or not a particular IP string
> satisfies a given CIDR range.
>
> How do you people solve this sort of problem?
>
> --
> "There should be a homonym exam before people are
> issued keyboards." -- George Moffitt
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/puppet-users?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.