1
|
module Actions
|
2
|
module ForemanPipeline
|
3
|
module JenkinsInstance
|
4
|
class Keyscan < AbstractJenkinsInstanceAction
|
5
|
def run
|
6
|
output[:status] = do_keyscan(parse_jenkins_hostname)
|
7
|
output[:command] = command
|
8
|
end
|
9
|
|
10
|
def do_keyscan(host)
|
11
|
ip = Socket::getaddrinfo(host, 'www', nil, Socket::SOCK_STREAM)[0][3]
|
12
|
status = nil
|
13
|
|
14
|
Net::SSH.start(ip, 'root', :keys => [input.fetch(:cert_path)]) do |ssh|
|
15
|
status = ssh_exec!(ssh, command)
|
16
|
end
|
17
|
status
|
18
|
end
|
19
|
|
20
|
def command
|
21
|
"ssh-keyscan #{input[:host_ip]} >> #{input[:jenkins_home]}/.ssh/known_hosts"
|
22
|
end
|
23
|
end
|
24
|
end
|
25
|
end
|
26
|
end
|