Add a prototype whohosts function for grouping machines at a common
authorStephen Gran <steve@lobefin.net>
Fri, 6 Nov 2009 22:06:20 +0000 (22:06 +0000)
committerStephen Gran <steve@lobefin.net>
Fri, 6 Nov 2009 22:06:20 +0000 (22:06 +0000)
hoster
Signed-off-by: Stephen Gran <steve@lobefin.net>
files/etc/puppet/lib/puppet/parser/functions/whohosts.rb [new file with mode: 0644]
manifests/site.pp
modules/debian-org/misc/hoster.yaml [new file with mode: 0644]

diff --git a/files/etc/puppet/lib/puppet/parser/functions/whohosts.rb b/files/etc/puppet/lib/puppet/parser/functions/whohosts.rb
new file mode 100644 (file)
index 0000000..e31688b
--- /dev/null
@@ -0,0 +1,28 @@
+module Puppet::Parser::Functions
+  newfunction(:whohosts, :type => :rvalue) do |args|
+    require 'ipaddr'
+    require 'yaml'
+
+    nodeinfo = args[0]
+    yamlfile = args[1]
+    parser.watch_file(yamlfile)
+
+    $KCODE = 'utf-8'
+
+    ans = "unknown"
+    yaml = YAML.load_file(yamlfile)
+
+    if (nodeinfo['ldap'].at(0)) and (nodeinfo['ldap'][0].has_key?('ipHostNumber'))
+      nodeinfo['ldap'][0]['ipHostNumber'].each do |addr|
+        yaml.keys.each do |hoster|
+          yaml[hoster].each do |net|
+            if IPAddr.new(net).include?(addr)
+              ans = hoster
+            end
+          end
+        end
+      end
+    end
+    return ans
+  end
+end
index b8f396b..b8dabd4 100644 (file)
@@ -15,6 +15,7 @@ Exec {
 
 node default {
     $nodeinfo = nodeinfo($fqdn, "/etc/puppet/modules/debian-org/misc/local.yaml")
+    $hoster   = whohosts($nodeinfo, "/etc/puppet/modules/debian-org/misc/hoster.yaml")
 
     include munin-node
     include sudo
diff --git a/modules/debian-org/misc/hoster.yaml b/modules/debian-org/misc/hoster.yaml
new file mode 100644 (file)
index 0000000..8a47956
--- /dev/null
@@ -0,0 +1,10 @@
+---
+darmstadt:
+  - 82.195.75.64/26
+  - 2001:41b8:202:deb::/64
+ftcollins:
+  - 192.25.206.0/24
+ubcece:
+  - 137.82.84.64/27
+  - 206.12.19.0/24
+---