Skip to content
This repository has been archived by the owner on Nov 23, 2017. It is now read-only.

Commit

Permalink
allow adding custom SSH known_hosts from a data bag
Browse files Browse the repository at this point in the history
My use case for this is for adding github.com so I can clone a repo I
need
  • Loading branch information
cap10morgan authored and jtimberman committed Mar 8, 2012
1 parent 3f0e490 commit d63b071
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
14 changes: 14 additions & 0 deletions ssh_known_hosts/recipes/default.rb
Expand Up @@ -23,6 +23,20 @@
nodes = search(:node, "keys_ssh:* NOT name:#{node.name}")
nodes << node

other_hosts = data_bag('ssh_known_hosts')
require 'resolv'
r = Resolv.new
other_hosts.each do |h|
host = data_bag_item('ssh_known_hosts', h)
host['ipaddress'] ||= r.getaddress(host['fqdn'])
host['keys'] = {
'ssh' => {}
}
host['keys']['ssh']['host_rsa_public'] = host['rsa'] if host.has_key?('rsa')
host['keys']['ssh']['host_dsa_public'] = host['dsa'] if host.has_key?('dsa')
nodes << host
end

template "/etc/ssh/ssh_known_hosts" do
source "known_hosts.erb"
mode 0444
Expand Down
8 changes: 6 additions & 2 deletions ssh_known_hosts/templates/default/known_hosts.erb
@@ -1,5 +1,9 @@
# THIS FILE IS MAINTAINED BY CHEF, DO NOT MODIFY AS IT WILL BE OVERWRITTEN
<% @nodes.each do |n| -%>
<%= n['hostname'] %>,<%= n['fqdn'] %>,<%= n['ipaddress'] %> ssh-rsa <%= n['keys']['ssh']['host_rsa_public'] %>
<%= n['hostname'] %>,<%= n['fqdn'] %>,<%= n['ipaddress'] %> ssh-dsa <%= n['keys']['ssh']['host_dsa_public'] %>
<% if n['keys']['ssh'].has_key?('host_rsa_public') -%>
<%= n.has_key?('hostname') ? "#{n['hostname']}," : '' %><%= n['fqdn'] %>,<%= n['ipaddress'] %> ssh-rsa <%= n['keys']['ssh']['host_rsa_public'] %>
<% end -%>
<% if n['keys']['ssh'].has_key?('host_dsa_public') -%>
<%= n.has_key?('hostname') ? "#{n['hostname']}," : '' %><%= n['fqdn'] %>,<%= n['ipaddress'] %> ssh-dsa <%= n['keys']['ssh']['host_dsa_public'] %>
<% end -%>
<% end -%>

0 comments on commit d63b071

Please sign in to comment.