Skip to content

Commit 15d0f5a

Browse files
committed
OpenSSH: install as part of VM setup, not WinRM
It appears that executing `Add-WindowsCapability` via WinRM is not viable, this commit moves the installation of OpenSSH.Server to the various IaaS pre-boot scrips which are not executed via WinRM. The installation of OpenSSSH.Server was added as follows: Azure: add a `custom_script` parameter to packer config AWS: added to `setup_winrm.txt` GCP: add to `setup-winrm.ps1` and use `sysprep-specialize-script-ps1`
1 parent 311be56 commit 15d0f5a

File tree

5 files changed

+37
-23
lines changed

5 files changed

+37
-23
lines changed

lib/packer/config/azure.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ def builders
4545
'winrm_use_ssl' => 'true',
4646
'winrm_insecure' => 'true',
4747
'winrm_timeout' => '1h',
48-
'winrm_username' => 'packer'
48+
'winrm_username' => 'packer',
49+
'custom_script' => 'powershell -ExecutionPolicy Unrestricted -NoProfile -NonInteractive -Command "Add-WindowsCapability -Online -Name (Get-WindowsCapability -Online -Name OpenSSH.Server* | ForEach-Object Name)"'
4950
}
5051
]
5152
end

lib/packer/config/gcp.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def initialize(
3939
end
4040

4141
def builders
42+
stemcell_builder_dir = File.expand_path('../../../../', __FILE__)
4243
[
4344
{
4445
'type' => 'googlecompute',
@@ -62,7 +63,7 @@ def builders
6263
'winrm_timeout' => '1h',
6364
'state_timeout' => '10m',
6465
'metadata' => {
65-
'sysprep-specialize-script-url' => 'https://raw.githubusercontent.com/cloudfoundry/bosh-windows-stemcell-builder/master/scripts/gcp/setup-winrm.ps1',
66+
'sysprep-specialize-script-ps1' => File.read(File.join(stemcell_builder_dir, 'scripts', 'gcp', 'setup-winrm.ps1')),
6667
'name' => "#{@vm_prefix}-#{Time.now.to_i}",
6768
}.compact_blank!
6869
}

scripts/aws/setup_winrm.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,10 @@ if (-not (Get-Command Enable-WinRM -errorAction SilentlyContinue))
3434
Write-Log "Invoking WinRM"
3535
Enable-WinRM
3636

37+
Write-Log "Install OpenSSH.Server"
38+
Write-Log (Get-WindowsCapability -Online -Name "OpenSSH.Server*" | Format-List | Out-String)
39+
Add-WindowsCapability -Online -Name (Get-WindowsCapability -Online -Name "OpenSSH.Server*" | ForEach-Object Name)
40+
Write-Log (Get-WindowsCapability -Online -Name "OpenSSH.Server*" | Format-List | Out-String)
41+
3742
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope LocalMachine
3843
</powershell>

scripts/gcp/setup-winrm.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,8 @@ if (-not (Get-Command Enable-WinRM -errorAction SilentlyContinue))
3232

3333
Write-Log "Invoking WinRM"
3434
Enable-WinRM
35+
36+
Write-Log "Install OpenSSH.Server"
37+
Write-Log (Get-WindowsCapability -Online -Name "OpenSSH.Server*" | Format-List | Out-String)
38+
Add-WindowsCapability -Online -Name (Get-WindowsCapability -Online -Name "OpenSSH.Server*" | ForEach-Object Name)
39+
Write-Log (Get-WindowsCapability -Online -Name "OpenSSH.Server*" | Format-List | Out-String)

spec/packer/config/gcp_spec.rb

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,30 @@
2222
vm_type: 'some-vm-type',
2323
).builders }
2424

25-
let (:baseline_builders) { {
26-
'type' => 'googlecompute',
27-
'credentials_json' => 'some-account-json',
28-
'project_id' => 'some-project-id',
29-
'tags' => ['winrm'],
30-
'source_image' => 'some-source-image',
31-
'image_family' => 'some-image-family',
32-
'zone' => 'us-west1-c',
33-
'disk_size' => 32,
34-
'machine_type' => 'some-vm-type',
35-
'omit_external_ip' => false,
36-
'communicator' => 'winrm',
37-
'winrm_username' => 'winrmuser',
38-
'winrm_use_ssl' => false,
39-
'winrm_timeout' => '1h',
40-
'state_timeout' => '10m',
41-
'metadata' => {
42-
'sysprep-specialize-script-url' => 'https://raw.githubusercontent.com/cloudfoundry/bosh-windows-stemcell-builder/master/scripts/gcp/setup-winrm.ps1',
43-
'name' => "some-vm-prefix-#{Time.now.to_i}"
44-
}
25+
let(:baseline_builders) do
26+
{
27+
'type' => 'googlecompute',
28+
'credentials_json' => 'some-account-json',
29+
'project_id' => 'some-project-id',
30+
'tags' => ['winrm'],
31+
'source_image' => 'some-source-image',
32+
'image_family' => 'some-image-family',
33+
'zone' => 'us-west1-c',
34+
'disk_size' => 32,
35+
'machine_type' => 'some-vm-type',
36+
'omit_external_ip' => false,
37+
'communicator' => 'winrm',
38+
'winrm_username' => 'winrmuser',
39+
'winrm_use_ssl' => false,
40+
'winrm_timeout' => '1h',
41+
'state_timeout' => '10m',
42+
'metadata' => {
43+
'sysprep-specialize-script-ps1' => anything,
44+
'name' => "some-vm-prefix-#{Time.now.to_i}"
45+
}
4546

46-
} }
47+
}
48+
end
4749

4850
context 'all os versions' do
4951
let(:os) { '' }

0 commit comments

Comments
 (0)