puppet 4 foo
[mirror/dsa-puppet.git] / modules / portforwarder / templates / authorized_keys.erb
index 985f367..ec11e54 100644 (file)
@@ -4,6 +4,13 @@
 ##
 
 <%=
+
+require 'digest/sha1'
+def get_local_ip_addr(host)
+       hash = Digest::SHA1.digest(host)
+       return '127.101.%d.%d'%[hash[0].ord, hash[1].ord]
+end
+
 def getportforwarderkey(host)
        key = nil
        begin
@@ -23,14 +30,14 @@ config.each_pair do |sourcehost, services|
        ##lines << "# sourcehost is #{sourcehost}"
        services.each do |service|
                ##lines << "# targethost is #{service['target_host']}, my hostname #{hostname}, fqdn is #{fqdn}"
-               next if service['target_host'] != fqdn
+               next if service['target_host'] != @fqdn
                allowed_ports << service['target_port'] if service['target_port']
        end
 
        if allowed_ports.length > 0
                sshkey = getportforwarderkey(sourcehost)
-               remote_ip = keyinfo[sourcehost]['ipHostNumber'].join(',')
-               local_bind = '127.101.%d.%d'%[ (sourcehost.hash / 256 % 256), sourcehost.hash % 256 ]
+               remote_ip = scope.lookupvar('site::allnodeinfo')[sourcehost]['ipHostNumber'].join(',')
+               local_bind = get_local_ip_addr(sourcehost)
 
                lines << "# from #{sourcehost}"
                if sshkey.nil? or remote_ip.nil? or local_bind.nil?