Sha256: 740266277af9b34468ba00eea19c1119d1af857c23d17e979d9dad54dec5f8ae
Contents?: true
Size: 1.51 KB
Versions: 16
Compression:
Stored size: 1.51 KB
Contents
require 'json' module Bourdain module Checks class SSHConfigCheck < Check usage :check, <<-END Ensure all nodes are enterened into the local SSH config ssh_config END def initialize cookbook_config super [] return unless require_chef! check_ssh_config! end private def check_ssh_config! ssh_config=File.join(ENV['HOME'], '.ssh', 'config') unless File::exist?(ssh_config) log.warn 'Skipping SSH config check. File does not exist: %s' % ssh_config.inspect return end nodes = Dir[File.join('nodes', '*.json')] nodes = nodes.map do |path| JSON::parse File.read(path) end config = File.read(ssh_config) hosts = [] config.lines.select do |l| l =~ /Host (\S+)/ hosts << $1 if $1 end unconfigured_nodes = nodes.select do |n| !hosts.include? n['name'] end File.open(ssh_config, 'a') do |f| f.puts unless unconfigured_nodes.empty? unconfigured_nodes.each do |n| log.info 'Adding %s to %s' % [ n['name'].inspect, ssh_config ] f.puts "Host %s" % n['name'] f.puts "\tHostName\t%s" % n['name'] f.puts "\tPort\t22" f.puts "\tUser\tvagrant" f.puts "\tStrictHostKeyChecking\tno" f.puts "\tIdentityFile\t~/.vagrant.d/insecure_private_key" f.puts end end end end end end
Version data entries
16 entries across 16 versions & 1 rubygems