Class: SimpleProvision::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_provision/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CLI



6
7
8
9
10
# File 'lib/simple_provision/cli.rb', line 6

def initialize(args)
  @profile = args[:profile]
  @username = args[:username]
  @host = args[:host]
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



5
6
7
# File 'lib/simple_provision/cli.rb', line 5

def host
  @host
end

#profileObject (readonly)

Returns the value of attribute profile.



5
6
7
# File 'lib/simple_provision/cli.rb', line 5

def profile
  @profile
end

#usernameObject (readonly)

Returns the value of attribute username.



5
6
7
# File 'lib/simple_provision/cli.rb', line 5

def username
  @username
end

Instance Method Details

#bootstrapObject



12
13
14
# File 'lib/simple_provision/cli.rb', line 12

def bootstrap
  SimpleProvision::SCP.new(username, host, options).copy_files
end

#configureObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/simple_provision/cli.rb', line 16

def configure
  begin
    Net::SSH.start(host, username, :forward_agent => true) do |ssh|
      ssh.exec! "tar -xzf #{SimpleProvision::SCP::FILENAME}"
      scripts = options.fetch(:scripts).each do |script|
        puts "Execute #{script}"
        ssh.open_channel do |ssh_channel|
          ssh_channel.request_pty
          ssh_channel.exec("#{environment_exports} bash -c '#{script}'") do |channel, success|
            unless success
              raise "Could not execute command: #{command.inspect}"
            end

            channel.on_data do |ch, data|
              STDOUT << data
            end

            channel.on_extended_data do |ch, type, data|
              next unless type == 1
              STDERR << data
            end
          end
        end
        ssh.loop
      end
    end
  rescue Net::SSH::HostKeyMismatch => exception
    exception.remember_host!
    sleep 0.2
    retry
  end
end