Class: Hocho::Drivers::ItamaeSsh

Inherits:
Base
  • Object
show all
Defined in:
lib/hocho/drivers/itamae_ssh.rb

Instance Attribute Summary

Attributes inherited from Base

#base_dir, #host, #initializers

Instance Method Summary collapse

Methods inherited from Base

#finalize, #run_list

Constructor Details

#initialize(host, base_dir: '.', initializers: [], itamae_options: []) ⇒ ItamaeSsh

Returns a new instance of ItamaeSsh.



7
8
9
10
# File 'lib/hocho/drivers/itamae_ssh.rb', line 7

def initialize(host, base_dir: '.', initializers: [], itamae_options: [])
  super host, base_dir: base_dir, initializers: initializers
  @itamae_options = itamae_options
end

Instance Method Details

#run(dry_run: false) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/hocho/drivers/itamae_ssh.rb', line 12

def run(dry_run: false)
  with_node_json_file do |node_json|
    env = {}.tap do |e|
      e['SUDO_PASSWORD'] = host.sudo_password if host.sudo_password
    end
    cmd = ["itamae", "ssh", *@itamae_options, "-j", node_json, "-h", host.hostname]

    cmd.push('-u', host.user) if host.user
    cmd.push('-p', host.ssh_port.to_s) if host.ssh_port
    cmd.push('--dry-run') if dry_run
    cmd.push('--color') if $stdout.tty?

    cmd.push(*run_list)

    puts "=> $ #{cmd.shelljoin}"
    system(env, *cmd, chdir: base_dir) or raise "itamae ssh failed"
  end
end