Class: Formatron::Chef::SSH

Inherits:
Object
  • Object
show all
Defined in:
lib/formatron/chef/ssh.rb

Overview

Perform commands on chef nodes over SSH

Constant Summary collapse

SSH_USER =
'ubuntu'

Instance Method Summary collapse

Constructor Details

#initialize(keys:) ⇒ SSH

Returns a new instance of SSH.



9
10
11
# File 'lib/formatron/chef/ssh.rb', line 9

def initialize(keys:)
  @keys = keys
end

Instance Method Details

#bootstrapped?(hostname:, bastion_hostname:) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/formatron/chef/ssh.rb', line 23

def bootstrapped?(hostname:, bastion_hostname:)
  Formatron::Util::SSH.exec(
    hostname: hostname,
    bastion_hostname: bastion_hostname,
    user: SSH_USER,
    key: @keys.ec2_key,
    command: '[ -f /etc/chef/client.pem ]'
  )
  true
rescue
  false
end

#run_chef_client(hostname:, bastion_hostname:) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/formatron/chef/ssh.rb', line 13

def run_chef_client(hostname:, bastion_hostname:)
  Formatron::Util::SSH.exec(
    hostname: hostname,
    bastion_hostname: bastion_hostname,
    user: SSH_USER,
    key: @keys.ec2_key,
    command: 'sudo chef-client'
  )
end