11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/devops_toolkit/tasks/ssh.rb', line 11
def known_hosts
full_known_hosts_path = File.expand_path(options[:known_hosts])
puts "Removing line #{options[:line]} from #{full_known_hosts_path}"
begin
if !options[:line].is_a?(Integer)
raise ArgumentError, 'line must be an integer'
end
lines = File.readlines(full_known_hosts_path).map {|l| l.strip}
deleted_line = lines.delete_at(options[:line] - 1)
puts "Deleted: #{deleted_line}"
File.write(full_known_hosts_path, "#{lines.join("\n")}\n")
rescue Exception => e
puts "#{e.class}: #{e.message}"
end
end
|