Sha256: be55a8c61b9b4ba86bd90993b801acb76d444da67bcae2e17e066fa1b3ab254f

Contents?: true

Size: 1.39 KB

Versions: 15

Compression:

Stored size: 1.39 KB

Contents

require 'optparse'

require "vagrant/util/safe_puts"

module Vagrant
  module Command
    class SSHConfig < Base
      include Util::SafePuts

      def execute
        options = {}

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

          opts.separator ""

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

        argv = parse_options(opts)
        return if !argv

        with_target_vms(argv, :single_target => 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"
          safe_puts(Util::TemplateRenderer.render(template, variables))
        end

        # Success, exit status 0
        0
       end
    end
  end
end

Version data entries

15 entries across 15 versions & 6 rubygems

Version Path
bmhatfield-vagrant-1.0.10 lib/vagrant/command/ssh_config.rb
bmhatfield-vagrant-1.0.9 lib/vagrant/command/ssh_config.rb
bmhatfield-vagrant-1.0.8 lib/vagrant/command/ssh_config.rb
bmhatfield-vagrant-1.0.7 lib/vagrant/command/ssh_config.rb
vagrantup-1.0.7 lib/vagrant/command/ssh_config.rb
vagrantup-1.0.6 lib/vagrant/command/ssh_config.rb
vagrantup-1.0.5 lib/vagrant/command/ssh_config.rb
vagrantup-1.0.4 lib/vagrant/command/ssh_config.rb
vagrant-fixed-ssh-1.0.7 lib/vagrant/command/ssh_config.rb
vagrant-1.0.7 lib/vagrant/command/ssh_config.rb
vagrant-1.0.6 lib/vagrant/command/ssh_config.rb
boxcar-0.10005.1 lib/vagrant/command/ssh_config.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/vagrant-1.0.5/lib/vagrant/command/ssh_config.rb
vagrant-1.0.5 lib/vagrant/command/ssh_config.rb
vagrant-1.0.4 lib/vagrant/command/ssh_config.rb