Class: Anvil::SshExecutor

Inherits:
Struct
  • Object
show all
Defined in:
lib/anvil/ssh_executor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hostnameObject

Returns the value of attribute hostname

Returns:

  • (Object)

    the current value of hostname



11
12
13
# File 'lib/anvil/ssh_executor.rb', line 11

def hostname
  @hostname
end

#loggerObject

Returns the value of attribute logger

Returns:

  • (Object)

    the current value of logger



11
12
13
# File 'lib/anvil/ssh_executor.rb', line 11

def logger
  @logger
end

#userObject

Returns the value of attribute user

Returns:

  • (Object)

    the current value of user



11
12
13
# File 'lib/anvil/ssh_executor.rb', line 11

def user
  @user
end

Instance Method Details

#call(&block) ⇒ Object



12
13
14
15
# File 'lib/anvil/ssh_executor.rb', line 12

def call &block
  @connection = Net::SSH.start hostname, user, use_agent: true, verify_host_key: :accept_new
  block.call self
end

#exec!(script, category = "") ⇒ Object



17
18
19
20
21
22
23
# File 'lib/anvil/ssh_executor.rb', line 17

def exec! script, category = ""
  @connection.exec! script do |channel, stream, data|
    data.to_s.split("\n") do |line|
      logger&.info line, category
    end
  end
end