Sha256: 40ee53d0e34d7fadb69ae830b6ed4e993d4be509bc99aabdc989384ec6c56e8f

Contents?: true

Size: 1.87 KB

Versions: 8

Compression:

Stored size: 1.87 KB

Contents

require 'optparse'

require "vagrant/util/safe_puts"

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

      def self.synopsis
        "outputs OpenSSH valid configuration to connect to the machine"
      end

      def execute
        options = {}

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

          o.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) 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],
            keys_only: ssh_info[:keys_only],
            paranoid: ssh_info[:paranoid],
            private_key_path: ssh_info[:private_key_path],
            log_level: ssh_info[:log_level],
            forward_agent: ssh_info[:forward_agent],
            forward_x11:   ssh_info[:forward_x11],
            proxy_command: ssh_info[:proxy_command],
            ssh_command:   ssh_info[:ssh_command],
            forward_env:   ssh_info[:forward_env],
          }

          # Render the template and output directly to STDOUT
          template = "commands/ssh_config/config"
          config   = Vagrant::Util::TemplateRenderer.render(template, variables)
          machine.ui.machine("ssh-config", config)
          safe_puts(config)
          safe_puts
        end

        # Success, exit status 0
        0
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
vagrant-unbundled-1.9.8.1 plugins/commands/ssh_config/command.rb
vagrant-unbundled-1.9.7.1 plugins/commands/ssh_config/command.rb
vagrant-aws-mkubenka-0.7.2.pre.14 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/commands/ssh_config/command.rb
vagrant-aws-mkubenka-0.7.2.pre.11 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/commands/ssh_config/command.rb
vagrant-aws-mkubenka-0.7.2.pre.10 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/commands/ssh_config/command.rb
vagrant-aws-mkubenka-0.7.2.pre.9 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/commands/ssh_config/command.rb
vagrant-unbundled-1.9.5.1 plugins/commands/ssh_config/command.rb
vagrant-unbundled-1.9.1.1 plugins/commands/ssh_config/command.rb