From 00c3a22cc611390e2b4a4cd9647e1edc5d8badae Mon Sep 17 00:00:00 2001 From: Stephen Gran Date: Fri, 6 Nov 2009 22:06:20 +0000 Subject: [PATCH] Add a prototype whohosts function for grouping machines at a common hoster Signed-off-by: Stephen Gran --- .../lib/puppet/parser/functions/whohosts.rb | 28 +++++++++++++++++++ manifests/site.pp | 1 + modules/debian-org/misc/hoster.yaml | 10 +++++++ 3 files changed, 39 insertions(+) create mode 100644 files/etc/puppet/lib/puppet/parser/functions/whohosts.rb create mode 100644 modules/debian-org/misc/hoster.yaml 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 index 000000000..e31688bad --- /dev/null +++ b/files/etc/puppet/lib/puppet/parser/functions/whohosts.rb @@ -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 diff --git a/manifests/site.pp b/manifests/site.pp index b8f396b91..b8dabd44d 100644 --- a/manifests/site.pp +++ b/manifests/site.pp @@ -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 index 000000000..8a479567d --- /dev/null +++ b/modules/debian-org/misc/hoster.yaml @@ -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 +--- -- 2.20.1