Sha256: e0401adf0fa04bc5a3be59f4836afdad9da3f26a3dfc10dab940d389d8d1933c

Contents?: true

Size: 1.27 KB

Versions: 16

Compression:

Stored size: 1.27 KB

Contents

require 'optparse'

module Vagrant
  module Command
    class SSHConfig < Base
      def execute
        options = {}

        opts = OptionParser.new do |opts|
          opts.banner = "Usage: vagrant ssh-config [vm-name] [-h name]"

          opts.separator ""

          opts.on("-h", "--host COMMAND", "Name the host for the config..") do |h|
            options[:host] = h
          end
        end

        argv = parse_options(opts)
        return if !argv

        with_target_vms(argv[0], true) do |vm|
          raise Errors::VMNotCreatedError if !vm.created?
          raise Errors::VMInaccessible if !vm.state == :inaccessible

          ssh_info  = vm.ssh.info
          variables = {
            :host_key => options[:host] || vm.name || "vagrant",
            :ssh_host => ssh_info[:host],
            :ssh_port => ssh_info[:port],
            :ssh_user => ssh_info[:username],
            :private_key_path => ssh_info[:private_key_path],
            :forward_agent => ssh_info[:forward_agent],
            :forward_x11   => ssh_info[:forward_x11]
          }

          # Render the template and output directly to STDOUT
          template = "commands/ssh_config/config"
          $stdout.puts(Util::TemplateRenderer.render(template, variables))
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
vagrantup-0.9.99.1 lib/vagrant/command/ssh_config.rb
vagrantup-0.9.7 lib/vagrant/command/ssh_config.rb
vagrantup-0.9.6 lib/vagrant/command/ssh_config.rb
vagrantup-0.9.5 lib/vagrant/command/ssh_config.rb
vagrantup-0.9.4 lib/vagrant/command/ssh_config.rb
vagrantup-0.9.3 lib/vagrant/command/ssh_config.rb
vagrantup-0.9.2 lib/vagrant/command/ssh_config.rb
vagrantup-0.9.1 lib/vagrant/command/ssh_config.rb
vagrantup-0.9.0 lib/vagrant/command/ssh_config.rb
vagrant-0.9.7 lib/vagrant/command/ssh_config.rb
vagrant-0.9.5 lib/vagrant/command/ssh_config.rb
vagrant-0.9.4 lib/vagrant/command/ssh_config.rb
vagrant-0.9.3 lib/vagrant/command/ssh_config.rb
vagrant-0.9.2 lib/vagrant/command/ssh_config.rb
vagrant-0.9.1 lib/vagrant/command/ssh_config.rb
vagrant-0.9.0 lib/vagrant/command/ssh_config.rb