Sha256: 10eba8c87cf49e2e9e8d1e4e535eccc9869ab5d9a620b6e40cb342c360b73f47

Contents?: true

Size: 1.38 KB

Versions: 19

Compression:

Stored size: 1.38 KB

Contents

require 'optparse'

require "vagrant/util/safe_puts"

module VagrantPlugins
  module CommandSSHConfig
    class Command < Vagrant.plugin("2", :command)
      include Vagrant::Util::SafePuts

      def execute
        options = {}

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

          o.on("--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, :single_target => true) do |machine|
          ssh_info = machine.ssh_info
          raise Vagrant::Errors::SSHNotReady if ssh_info.nil?

          variables = {
            :host_key => options[:host] || machine.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(Vagrant::Util::TemplateRenderer.render(template, variables))
        end

        # Success, exit status 0
        0
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 6 rubygems

Version Path
tamtam-vagrant-reload-1.1.3 vendor/cache/vagrant-0ac2a8738841/plugins/commands/ssh_config/command.rb
tamtam-vagrant-reload-1.1.2 vendor/cache/vagrant-0ac2a8738841/plugins/commands/ssh_config/command.rb
tamtam-vagrant-reload-1.1.1 vendor/cache/vagrant-0ac2a8738841/plugins/commands/ssh_config/command.rb
tamtam-vagrant-reload-1.1 vendor/cache/vagrant-0ac2a8738841/plugins/commands/ssh_config/command.rb
tnargav-1.3.6 plugins/commands/ssh_config/command.rb
tnargav-1.3.3 plugins/commands/ssh_config/command.rb
vagrant-shell-0.2.9 demo/templates/vendor/bundle/ruby/1.9.1/gems/tnargav-1.2.2/plugins/commands/ssh_config/command.rb
tnargav-1.2.3 plugins/commands/ssh_config/command.rb
vagrant-shell-0.2.8 demo/templates/vendor/bundle/ruby/1.9.1/gems/tnargav-1.2.2/plugins/commands/ssh_config/command.rb
vagrant-shell-0.2.6 vendor/bundle/gems/tnargav-1.2.2/plugins/commands/ssh_config/command.rb
vagrant-shell-0.2.5 vendor/bundle/gems/tnargav-1.2.2/plugins/commands/ssh_config/command.rb
tnargav-1.2.2 plugins/commands/ssh_config/command.rb
vagrantup-1.1.3 plugins/commands/ssh_config/command.rb
vagrantup-1.1.2 plugins/commands/ssh_config/command.rb
vagrantup-1.1.1 plugins/commands/ssh_config/command.rb
vagrantup-1.1.0 plugins/commands/ssh_config/command.rb
vagrantup-1.1.4 plugins/commands/ssh_config/command.rb
vagrant-actionio-0.0.9 vendor/bundle/bundler/gems/vagrant-c74251a1d9c0/plugins/commands/ssh_config/command.rb
vagrant-lxc-0.0.1 vendor/vagrant/plugins/commands/ssh_config/command.rb