Class: VagrantPlugins::CORL::Action::InitKeys

Inherits:
BaseAction
  • Object
show all
Defined in:
lib/core/vagrant/actions/init_keys.rb

Instance Attribute Summary

Attributes inherited from BaseAction

#network, #node, #vm

Instance Method Summary collapse

Methods inherited from BaseAction

#initialize

Constructor Details

This class inherits a constructor from VagrantPlugins::CORL::BaseAction

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/core/vagrant/actions/init_keys.rb', line 7

def call(env)
  super do
    env[:ui].info I18n.t("corl.vagrant.actions.init_keys.start")
    
    if node.public_key
      ssh_key = ::CORL::Util::Disk.read(node.public_key)
      
      if ssh_key && ! ssh_key.empty?
        vm.communicate.tap do |comm|
          comm.execute("echo '#{ssh_key}' > \$HOME/.ssh/authorized_keys")
        end
        node.set_cache_setting(:use_private_key, true)
        env[:machine].config.ssh.private_key_path = node.private_key
        
        node.machine.load
      end
    end      
    @app.call env
  end
end