Class: Bard::Provision::SSH

Inherits:
Bard::Provision show all
Defined in:
lib/bard/provision/ssh.rb

Overview

move ssh port add to known hosts

Instance Attribute Summary

Attributes inherited from Bard::Provision

#config, #ssh_url

Instance Method Summary collapse

Methods inherited from Bard::Provision

call

Instance Method Details

#callObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/bard/provision/ssh.rb', line 5

def call
  print "SSH:"

  if !ssh_available?(provision_server.ssh_uri, port: target_port)
    if !ssh_available?(provision_server.ssh_uri)
      raise "can't find SSH on port #{target_port} or #{provision_server.ssh_uri.port || 22}"
    end
    if !ssh_known_host?(provision_server.ssh_uri)
      print " Adding known host,"
      add_ssh_known_host!(provision_server.ssh_uri)
    end
    print " Reconfiguring port to #{target_port},"
    provision_server.run! %(echo "Port #{target_port}" | sudo tee /etc/ssh/sshd_config.d/port_#{target_port}.conf; sudo service ssh restart), home: true
  end

  if !ssh_known_host?(provision_server.ssh_uri)
    print " Adding known host,"
    add_ssh_known_host!(provision_server.ssh_uri)
  end

  # provision with new target port from now on
  ssh_url.gsub!(/:\d+$/, "")
  ssh_url << ":#{target_port}"
  puts ""
end