From: Peter Palfrader Date: Tue, 1 Mar 2011 10:50:22 +0000 (+0100) Subject: Try returning an info hash for a hoster - this will fail X-Git-Url: https://git.donarmstrong.com/?p=dsa-puppet.git;a=commitdiff_plain;h=a07d3c87c702f358bd36d52f423c1f437307b015 Try returning an info hash for a hoster - this will fail --- diff --git a/manifests/site.pp b/manifests/site.pp index 3e5e5f31..895a84dd 100644 --- a/manifests/site.pp +++ b/manifests/site.pp @@ -16,10 +16,10 @@ Exec { node default { $localinfo = yamlinfo('*', "/etc/puppet/modules/debian-org/misc/local.yaml") $nodeinfo = nodeinfo($fqdn, "/etc/puppet/modules/debian-org/misc/local.yaml") - $hoster = whohosts($nodeinfo, "/etc/puppet/modules/debian-org/misc/hoster.yaml") + $hosterinfo = whohosts($nodeinfo, "/etc/puppet/modules/debian-org/misc/hoster.yaml") $keyinfo = allnodeinfo("sshRSAHostKey", "ipHostNumber", "purpose") $mxinfo = allnodeinfo("mXRecord") - notice("hoster for ${fqdn} is ${hoster}") + notice("hoster for ${fqdn} is ${getfromhash(hosterinfo, "name")}") include munin-node include syslog-ng @@ -122,7 +122,7 @@ node default { case $brokenhosts { "true": { include hosts } } - case $hoster { + case getfromhash($hosterinfo, "name") { "ubcece", "darmstadt", "ftcollins", "grnet": { include resolv } } case $portforwarder_user_exists { diff --git a/modules/puppetmaster/lib/puppet/parser/functions/getfromhash.rb b/modules/puppetmaster/lib/puppet/parser/functions/getfromhash.rb new file mode 100644 index 00000000..e948929d --- /dev/null +++ b/modules/puppetmaster/lib/puppet/parser/functions/getfromhash.rb @@ -0,0 +1,18 @@ +module Puppet::Parser::Functions + newfunction(:getfromhash, :type => :rvalue) do |args| + h = args.shift + key = args.shift + + raise Puppet::ParseError, "argument is not a hash" unless h.kind_of?(Hash) + if h.has_key?(key) + ans = h[key] + else + ans = false + end + + return ans + end +end +# vim:set et: +# vim:set sts=2 ts=2: +# vim:set shiftwidth=2: diff --git a/modules/puppetmaster/lib/puppet/parser/functions/whohosts.rb b/modules/puppetmaster/lib/puppet/parser/functions/whohosts.rb index 780afa1d..022ca895 100644 --- a/modules/puppetmaster/lib/puppet/parser/functions/whohosts.rb +++ b/modules/puppetmaster/lib/puppet/parser/functions/whohosts.rb @@ -9,7 +9,7 @@ module Puppet::Parser::Functions $KCODE = 'utf-8' - ans = "unknown" + ans = {"name": "unknown"} yaml = YAML.load_file(yamlfile) if (nodeinfo['ldap'].has_key?('ipHostNumber')) @@ -24,7 +24,8 @@ module Puppet::Parser::Functions netrange.each do |net| begin if IPAddr.new(net).include?(addr) - ans = hoster + ans = yaml[hoster] + ans['name'] = hoster end rescue Exception => e raise "Error while trying to match addr #{addr} for net #{net}: #{e.message}\n#{e.backtrace}" diff --git a/modules/resolv/templates/resolv.conf.erb b/modules/resolv/templates/resolv.conf.erb index 84c98368..e5ddafe0 100644 --- a/modules/resolv/templates/resolv.conf.erb +++ b/modules/resolv/templates/resolv.conf.erb @@ -8,7 +8,7 @@ nameservers = [] searchpaths = [] resolvconf = '' -case hoster +case hosterinfo["name"] when "darmstadt" then case hostname when "draghi", "liszt" then diff --git a/modules/ssh/templates/authorized_keys.erb b/modules/ssh/templates/authorized_keys.erb index 2d991521..2a546ebe 100644 --- a/modules/ssh/templates/authorized_keys.erb +++ b/modules/ssh/templates/authorized_keys.erb @@ -1,5 +1,5 @@ # local admin -<%= hosterkeys = case hoster +<%= hosterkeys = case hosterinfo['name'] when "ubcece" then "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAvEEyxznxleAhk98K7SkAeAKWibijL5uFjIl1+tr8rz+XmFsjabTK2+hQXkgzmU+jqQ2+MPp6btfAq9Oe27GQYWUFfsAZMRb907dReFQYPKbPhQZoo5LUfkrCiR3tD0Nm2JfepTV0079K1+Q50EMImttwbI94FfSoSgTxgF4rCoLpUgmF0IHDR1+kTGow7YnuS1Y/I1zKAbofg8KBGXOLArkcZbxArt25Y2wlnE+ZHIb3Rn3pYc3/KmPPvEQy9IkR/uzzkWSaCBVMFJEO0ejjWrV4HR64GlKUPQ0CekSYn1EErY55CF5sWkasXhflluwSf7b+/jedDM1A1Vrp9Z/F8Q== chrisd" end