diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cd105f62..1cde000bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ IMPROVEMENTS: + - core: Automatically forward WinRM port if communicator is + WinRM. [GH-3685] - command/rdp: Args after "--" are passed directly through to the RDP client. [GH-3686] - providers/docker: `build_args` config to specify extra args for diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index 7e0803756..c7a1e6024 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -358,7 +358,16 @@ module VagrantPlugins define(DEFAULT_VM_NAME) if defined_vm_keys.empty? # Make sure the SSH forwarding is added if it doesn't exist - if !@__networks["forwarded_port-ssh"] + if @communicator == :winrm + if !@__networks["forwarded_port-winrm"] + network :forwarded_port, + guest: 5985, + host: 55985, + host_ip: "127.0.0.1", + id: "winrm", + auto_correct: true + end + elsif !@__networks["forwarded_port-ssh"] network :forwarded_port, guest: 22, host: 2222, diff --git a/test/unit/plugins/kernel_v2/config/vm_test.rb b/test/unit/plugins/kernel_v2/config/vm_test.rb index 9c80dadcb..f2e797cdd 100644 --- a/test/unit/plugins/kernel_v2/config/vm_test.rb +++ b/test/unit/plugins/kernel_v2/config/vm_test.rb @@ -145,7 +145,7 @@ describe VagrantPlugins::Kernel_V2::VMConfig do end describe "#network(s)" do - it "defaults to forwarding SSH" do + it "defaults to forwarding SSH by default" do subject.finalize! n = subject.networks expect(n.length).to eq(1) @@ -156,6 +156,18 @@ describe VagrantPlugins::Kernel_V2::VMConfig do expect(n[0][1][:id]).to eq("ssh") end + it "defaults to forwarding WinRM if communicator is winrm" do + subject.communicator = "winrm" + subject.finalize! + n = subject.networks + expect(n.length).to eq(1) + expect(n[0][0]).to eq(:forwarded_port) + expect(n[0][1][:guest]).to eq(5985) + expect(n[0][1][:host]).to eq(55985) + expect(n[0][1][:host_ip]).to eq("127.0.0.1") + expect(n[0][1][:id]).to eq("winrm") + end + it "allows overriding SSH" do subject.network "forwarded_port", guest: 22, host: 14100, id: "ssh" @@ -169,6 +181,20 @@ describe VagrantPlugins::Kernel_V2::VMConfig do expect(n[0][1][:id]).to eq("ssh") end + it "allows overriding WinRM" do + subject.communicator = :winrm + subject.network "forwarded_port", + guest: 22, host: 14100, id: "winrm" + subject.finalize! + + n = subject.networks + expect(n.length).to eq(1) + expect(n[0][0]).to eq(:forwarded_port) + expect(n[0][1][:guest]).to eq(22) + expect(n[0][1][:host]).to eq(14100) + expect(n[0][1][:id]).to eq("winrm") + end + it "turns all forwarded port ports to ints" do subject.network "forwarded_port", guest: "45", host: "4545", id: "test"