summaryrefslogtreecommitdiff
path: root/lib/leap_cli/config
diff options
context:
space:
mode:
Diffstat (limited to 'lib/leap_cli/config')
-rw-r--r--lib/leap_cli/config/macros.rb67
1 files changed, 40 insertions, 27 deletions
diff --git a/lib/leap_cli/config/macros.rb b/lib/leap_cli/config/macros.rb
index 69c3049..386bce3 100644
--- a/lib/leap_cli/config/macros.rb
+++ b/lib/leap_cli/config/macros.rb
@@ -165,31 +165,35 @@ module LeapCli; module Config
# Also, for virtual machines, we use the local address if this @node is in
# the same location as the node in question.
#
+ # We include the ssh public key for each host, so that the hash can also
+ # be used to generate the /etc/ssh/known_hosts
+ #
def hosts_file(nodes=nil)
if nodes.nil?
if @referenced_nodes && @referenced_nodes.any?
nodes = @referenced_nodes
end
end
- if nodes
- hosts = {}
- my_location = @node['location'] ? @node['location']['name'] : nil
- nodes.each_node do |node|
- next if node.name == @node.name
- hosts[node.name] = {'ip_address' => node.ip_address, 'domain_internal' => node.domain.internal, 'domain_full' => node.domain.full}
- node_location = node['location'] ? node['location']['name'] : nil
- if my_location == node_location
- if facts = @node.manager.facts[node.name]
- if facts['ec2_public_ipv4']
- hosts[node.name]['ip_address'] = facts['ec2_public_ipv4']
- end
+ return nil unless nodes
+ hosts = {}
+ my_location = @node['location'] ? @node['location']['name'] : nil
+ nodes.each_node do |node|
+ next if node.name == @node.name
+ hosts[node.name] = {'ip_address' => node.ip_address, 'domain_internal' => node.domain.internal, 'domain_full' => node.domain.full}
+ node_location = node['location'] ? node['location']['name'] : nil
+ if my_location == node_location
+ if facts = @node.manager.facts[node.name]
+ if facts['ec2_public_ipv4']
+ hosts[node.name]['ip_address'] = facts['ec2_public_ipv4']
end
end
end
- return hosts
- else
- return nil
+ host_pub_key = Util::read_file([:node_ssh_pub_key,node.name])
+ if host_pub_key
+ hosts[node.name]['host_pub_key'] = host_pub_key
+ end
end
+ hosts
end
##
@@ -347,18 +351,27 @@ module LeapCli; module Config
hash
end
- def known_hosts_file
- return nil unless @referenced_nodes
- entries = []
- @referenced_nodes.each_node do |node|
- hostnames = [node.name, node.domain.internal, node.domain.full, node.ip_address].join(',')
- pub_key = Util::read_file([:node_ssh_pub_key,node.name])
- if pub_key
- entries << [hostnames, pub_key].join(' ')
- end
- end
- entries.join("\n")
- end
+ #
+ # this is not currently used, because we put key information in the 'hosts' hash.
+ # see 'hosts_file()'
+ #
+ # def known_hosts_file(nodes=nil)
+ # if nodes.nil?
+ # if @referenced_nodes && @referenced_nodes.any?
+ # nodes = @referenced_nodes
+ # end
+ # end
+ # return nil unless nodes
+ # entries = []
+ # nodes.each_node do |node|
+ # hostnames = [node.name, node.domain.internal, node.domain.full, node.ip_address].join(',')
+ # pub_key = Util::read_file([:node_ssh_pub_key,node.name])
+ # if pub_key
+ # entries << [hostnames, pub_key].join(' ')
+ # end
+ # end
+ # entries.join("\n")
+ # end
##
## UTILITY