Sha256: cb70e74f0feef59d38b70c0ef6e800a43ed380b6203bc94ea831c8dace07b790

Contents?: true

Size: 1.25 KB

Versions: 16

Compression:

Stored size: 1.25 KB

Contents

module Vagrant
  class Commands
    # Outputs a valid entry for .ssh/config which can be used to connect
    # to this environment.
    class SSHConfig < Base
      Base.subcommand "ssh-config", self
      description "outputs .ssh/config valid syntax for connecting to this environment via ssh"

      def execute(args=[])
        env.require_root_path

        args = parse_options(args)
        show_single(args[0])
      end

      def show_single(name)
        if name.nil? && env.multivm?
          error_and_exit(:ssh_config_multivm)
          return # for tests
        end

        vm = name.nil? ? env.vms.values.first : env.vms[name.to_sym]
        if vm.nil?
          error_and_exit(:unknown_vm, :vm => name)
          return # for tests
        end

        puts TemplateRenderer.render("ssh_config", {
          :host_key => options[:host] || "vagrant",
          :ssh_user => vm.env.config.ssh.username,
          :ssh_port => vm.ssh.port,
          :private_key_path => vm.env.config.ssh.private_key_path
        })
      end

      def options_spec(opts)
        opts.banner = "Usage: vagrant ssh-config [--host NAME]"

        opts.on("-h", "--host [HOST]", "Host name for the SSH config") do |h|
          options[:host] = h
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
vagrantup-0.5.4 lib/vagrant/commands/ssh_config.rb
vagrantup-0.5.3 lib/vagrant/commands/ssh_config.rb
vagrantup-0.5.2 lib/vagrant/commands/ssh_config.rb
vagrantup-0.5.1 lib/vagrant/commands/ssh_config.rb
vagrantup-0.5.0 lib/vagrant/commands/ssh_config.rb
vagrantup-0.4.3.dev lib/vagrant/commands/ssh_config.rb
vagrantup-0.4.1 lib/vagrant/commands/ssh_config.rb
vagrantup-0.4.0 lib/vagrant/commands/ssh_config.rb
vagrant-0.5.4 lib/vagrant/commands/ssh_config.rb
vagrant-0.5.3 lib/vagrant/commands/ssh_config.rb
vagrant-0.5.2 lib/vagrant/commands/ssh_config.rb
vagrant-0.5.1 lib/vagrant/commands/ssh_config.rb
vagrant-0.5.0 lib/vagrant/commands/ssh_config.rb
vagrant-0.4.2 lib/vagrant/commands/ssh_config.rb
vagrant-0.4.1 lib/vagrant/commands/ssh_config.rb
vagrant-0.4.0 lib/vagrant/commands/ssh_config.rb