rgl / packer-plugin-windows-update

Packer plugin for installing Windows updates
Mozilla Public License 2.0
299 stars 71 forks source link

windows-update arent working #98

Closed jbpoint closed 3 years ago

jbpoint commented 3 years ago

Hi,

i have an ubuntu with packer 1.7.3, Windows VM builds, but updates not.

provisioner "windows-update" { pause_before = "30s" searchcriteria = "IsInstalled=0" filters = [ "exclude:$.Title -like 'VMware'", "exclude:$.Title -like 'Preview'", "exclude:$.Title -like 'Defender'", "include:$true" ]

/root/.packer.d/plugins/packer-provisioner-windows-update

`2021/07/13 08:20:25 [INFO] Packer version: 1.7.3 [go1.16.5 linux amd64] 2021/07/13 08:20:25 [TRACE] discovering plugins in /usr/bin 2021/07/13 08:20:25 [DEBUG] Discovered plugin: windows-update_v0.12.0_x5.0_linux_amd64 = /usr/bin/packer-plugin-windows-update_v0.12.0_x5.0_linux_amd64 2021/07/13 08:20:25 found external [-packer-default-plugin-name-] provisioner from windows-update_v0.12.0_x5.0_linux_amd64 plugin 2021/07/13 08:20:25 [TRACE] discovering plugins in /root/.packer.d/plugins 2021/07/13 08:20:25 [DEBUG] Discovered plugin: windows-update = /root/.packer.d/plugins/packer-provisioner-windows-update 2021/07/13 08:20:25 using external provisioners [windows-update] 2021/07/13 08:20:25 [TRACE] discovering plugins in . 2021/07/13 08:20:25 [INFO] PACKER_CONFIG env var not set; checking the default config file path 2021/07/13 08:20:25 [INFO] PACKER_CONFIG env var set; attempting to open config file: /root/.packerconfig 2021/07/13 08:20:25 [WARN] Config file doesn't exist: /root/.packerconfig 2021/07/13 08:20:25 [INFO] Setting cache directory: /root/packer-vsphere/builds/windows/windows-server-2019/packer_cache 2021/07/13 08:20:25 [TRACE] validateValue: not active for vcenter_folder, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for iso_datastore, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for iso_checksum, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vm_disk_controller_type, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vm_shutdown_command, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vcenter_server, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vcenter_cluster, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vm_version, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vm_boot_wait, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vm_cdrom_type, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vm_disk_size, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vm_floppy_files_server_std_dexp, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vm_floppy_files_server_dc_dexp, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for build_password, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for powershell_scripts, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vcenter_insecure_connection, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vcenter_datacenter, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vcenter_content_library, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for iso_path, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for iso_file, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vm_guest_os_edition_std, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vm_guest_os_type, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vm_network_card, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vcenter_password, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vm_guest_os_edition_dc, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vm_floppy_files_server_std_core, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for powershell_inline, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vm_guest_os_family, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vm_floppy_files_server_dc_core, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vm_boot_command, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vcenter_datastore, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vm_guest_os_member, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vm_guest_os_version, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vm_cpu_sockets, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vm_cpu_cores, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for build_username, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vcenter_network, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vm_firmware, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vm_mem_size, so skipping 2021/07/13 08:20:25 [TRACE] validateValue: not active for vcenter_username, so skipping 2021/07/13 08:20:25 [TRACE] Starting internal plugin packer-builder-vsphere-iso 2021/07/13 08:20:25 Starting plugin: /usr/bin/packer []string{"/usr/bin/packer", "plugin", "packer-builder-vsphere-iso"} 2021/07/13 08:20:25 Waiting for RPC address for: /usr/bin/packer 2021/07/13 08:20:25 packer-builder-vsphere-iso plugin: [INFO] Packer version: 1.7.3 [go1.16.5 linux amd64] 2021/07/13 08:20:25 packer-builder-vsphere-iso plugin: [INFO] PACKER_CONFIG env var not set; checking the default config file path 2021/07/13 08:20:25 packer-builder-vsphere-iso plugin: [INFO] PACKER_CONFIG env var set; attempting to open config file: /root/.packerconfig 2021/07/13 08:20:25 packer-builder-vsphere-iso plugin: [WARN] Config file doesn't exist: /root/.packerconfig 2021/07/13 08:20:25 packer-builder-vsphere-iso plugin: [INFO] Setting cache directory: /root/packer-vsphere/builds/windows/windows-server-2019/packer_cache 2021/07/13 08:20:25 packer-builder-vsphere-iso plugin: args: []string{"packer-builder-vsphere-iso"} 2021/07/13 08:20:25 packer-builder-vsphere-iso plugin: Plugin address: unix /tmp/packer-plugin413156741 2021/07/13 08:20:25 packer-builder-vsphere-iso plugin: Waiting for connection... 2021/07/13 08:20:25 Received unix RPC address for /usr/bin/packer: addr is /tmp/packer-plugin413156741 2021/07/13 08:20:25 packer-builder-vsphere-iso plugin: Serving a plugin connection... 2021/07/13 08:20:25 [TRACE] Starting internal plugin packer-provisioner-file 2021/07/13 08:20:25 Starting plugin: /usr/bin/packer []string{"/usr/bin/packer", "plugin", "packer-provisioner-file"} 2021/07/13 08:20:25 Waiting for RPC address for: /usr/bin/packer 2021/07/13 08:20:26 packer-provisioner-file plugin: [INFO] Packer version: 1.7.3 [go1.16.5 linux amd64] 2021/07/13 08:20:26 packer-provisioner-file plugin: [INFO] PACKER_CONFIG env var not set; checking the default config file path 2021/07/13 08:20:26 packer-provisioner-file plugin: [INFO] PACKER_CONFIG env var set; attempting to open config file: /root/.packerconfig 2021/07/13 08:20:26 packer-provisioner-file plugin: [WARN] Config file doesn't exist: /root/.packerconfig 2021/07/13 08:20:26 packer-provisioner-file plugin: [INFO] Setting cache directory: /root/packer-vsphere/builds/windows/windows-server-2019/packer_cache 2021/07/13 08:20:26 packer-provisioner-file plugin: args: []string{"packer-provisioner-file"} 2021/07/13 08:20:26 packer-provisioner-file plugin: Plugin address: unix /tmp/packer-plugin548339777 2021/07/13 08:20:26 packer-provisioner-file plugin: Waiting for connection... 2021/07/13 08:20:26 Received unix RPC address for /usr/bin/packer: addr is /tmp/packer-plugin548339777 2021/07/13 08:20:26 packer-provisioner-file plugin: Serving a plugin connection... 2021/07/13 08:20:26 [TRACE] Starting internal plugin packer-provisioner-powershell 2021/07/13 08:20:26 Starting plugin: /usr/bin/packer []string{"/usr/bin/packer", "plugin", "packer-provisioner-powershell"} 2021/07/13 08:20:26 Waiting for RPC address for: /usr/bin/packer 2021/07/13 08:20:26 packer-provisioner-powershell plugin: [INFO] Packer version: 1.7.3 [go1.16.5 linux amd64] 2021/07/13 08:20:26 packer-provisioner-powershell plugin: [INFO] PACKER_CONFIG env var not set; checking the default config file path 2021/07/13 08:20:26 packer-provisioner-powershell plugin: [INFO] PACKER_CONFIG env var set; attempting to open config file: /root/.packerconfig 2021/07/13 08:20:26 packer-provisioner-powershell plugin: [WARN] Config file doesn't exist: /root/.packerconfig 2021/07/13 08:20:26 packer-provisioner-powershell plugin: [INFO] Setting cache directory: /root/packer-vsphere/builds/windows/windows-server-2019/packer_cache 2021/07/13 08:20:26 packer-provisioner-powershell plugin: args: []string{"packer-provisioner-powershell"} 2021/07/13 08:20:26 packer-provisioner-powershell plugin: Plugin address: unix /tmp/packer-plugin237431897 2021/07/13 08:20:26 packer-provisioner-powershell plugin: Waiting for connection... 2021/07/13 08:20:26 Received unix RPC address for /usr/bin/packer: addr is /tmp/packer-plugin237431897 2021/07/13 08:20:26 packer-provisioner-powershell plugin: Serving a plugin connection... 2021/07/13 08:20:26 [TRACE] Starting internal plugin packer-provisioner-powershell 2021/07/13 08:20:26 Starting plugin: /usr/bin/packer []string{"/usr/bin/packer", "plugin", "packer-provisioner-powershell"} 2021/07/13 08:20:26 Waiting for RPC address for: /usr/bin/packer 2021/07/13 08:20:26 packer-provisioner-powershell plugin: [INFO] Packer version: 1.7.3 [go1.16.5 linux amd64] 2021/07/13 08:20:26 packer-provisioner-powershell plugin: [INFO] PACKER_CONFIG env var not set; checking the default config file path 2021/07/13 08:20:26 packer-provisioner-powershell plugin: [INFO] PACKER_CONFIG env var set; attempting to open config file: /root/.packerconfig 2021/07/13 08:20:26 packer-provisioner-powershell plugin: [WARN] Config file doesn't exist: /root/.packerconfig 2021/07/13 08:20:26 packer-provisioner-powershell plugin: [INFO] Setting cache directory: /root/packer-vsphere/builds/windows/windows-server-2019/packer_cache 2021/07/13 08:20:26 packer-provisioner-powershell plugin: args: []string{"packer-provisioner-powershell"} 2021/07/13 08:20:26 packer-provisioner-powershell plugin: Plugin address: unix /tmp/packer-plugin194505063 2021/07/13 08:20:26 packer-provisioner-powershell plugin: Waiting for connection... 2021/07/13 08:20:26 Received unix RPC address for /usr/bin/packer: addr is /tmp/packer-plugin194505063 2021/07/13 08:20:26 packer-provisioner-powershell plugin: Serving a plugin connection... 2021/07/13 08:20:26 [TRACE] Starting external plugin /root/.packer.d/plugins/packer-provisioner-windows-update 2021/07/13 08:20:26 Starting plugin: /root/.packer.d/plugins/packer-provisioner-windows-update []string{"/root/.packer.d/plugins/packer-provisioner-windows-update"} 2021/07/13 08:20:26 Waiting for RPC address for: /root/.packer.d/plugins/packer-provisioner-windows-update 2021/07/13 08:20:26 packer-provisioner-windows-update plugin: 2021/07/13 08:20:26 Starting packer-plugin-windows-update (version 0.12.0; commit ed5cb10b6e5857c4d85747ca4aa43f07ef30c727; date 2021-04-18T21:07:09Z) 2021/07/13 08:20:26 packer-provisioner-windows-update plugin: 2021/07/13 08:20:26 Failed to start: needs at least one argument 2021/07/13 08:20:26 /root/.packer.d/plugins/packer-provisioner-windows-update: plugin process exited

on windows-server-2019.pkr.hcl line 426: (source code not available)

plugin exited before we could connect

2021/07/13 08:20:26 Build debug mode: false 2021/07/13 08:20:26 Force build: true 2021/07/13 08:20:26 On error: 2021/07/13 08:20:26 Waiting on builds to complete... ==> Wait completed after 20 microseconds ==> Builds finished but no artifacts were created. 2021/07/13 08:20:26 [INFO] (telemetry) Finalizing. Error: failed loading windows-update

on windows-server-2019.pkr.hcl line 426: (source code not available)

plugin exited before we could connect

==> Wait completed after 20 microseconds

==> Builds finished but no artifacts were created. 2021/07/13 08:20:26 waiting for all plugin processes to complete... 2021/07/13 08:20:26 /usr/bin/packer: plugin process exited 2021/07/13 08:20:26 /usr/bin/packer: plugin process exited 2021/07/13 08:20:26 /usr/bin/packer: plugin process exited 2021/07/13 08:20:26 /usr/bin/packer: plugin process exited `

rgl commented 3 years ago

I have no idea why packer is not passing tru the expected arguments to the plugin as displayed in your logs:

2021/07/13 08:20:26 [TRACE] Starting external plugin /root/.packer.d/plugins/packer-provisioner-windows-update
2021/07/13 08:20:26 Starting plugin: /root/.packer.d/plugins/packer-provisioner-windows-update []string{"/root/.packer.d/plugins/packer-provisioner-windows-update"}
2021/07/13 08:20:26 Waiting for RPC address for: /root/.packer.d/plugins/packer-provisioner-windows-update
2021/07/13 08:20:26 packer-provisioner-windows-update plugin: 2021/07/13 08:20:26 Starting packer-plugin-windows-update (version 0.12.0; commit ed5cb10; date 2021-04-18T21:07:09Z)
2021/07/13 08:20:26 packer-provisioner-windows-update plugin: 2021/07/13 08:20:26 Failed to start: needs at least one argument
2021/07/13 08:20:26 /root/.packer.d/plugins/packer-provisioner-windows-update: plugin process exited

Instead of building this plugin from source, can you first try with the pre-built version by using the following block in your packer template?

packer {
  required_plugins {
    windows-update = {
      version = "0.12.0"
      source = "github.com/rgl/windows-update"
    }
  }
}

Also make sure (in the packer logs) that packer is loading the expected plugin binary (from ~/.packer.d/plugins/github.com/rgl/windows-update/). Packer should log something like:

2021/07/13 16:25:52 [TRACE] listing potential installations for "github.com/rgl/windows-update" that match "0.12.0". plugingetter.ListInstallationsOptions{FromFolders:[]string{"/usr/local/bin/packer", ".", "/home/rgl/.packer.d/plugins"}, BinaryInstallationOptions:plugingetter.BinaryInstallationOptions{APIVersionMajor:"5", APIVersionMinor:"0", OS:"linux", ARCH:"amd64", Ext:"", Checksummers:[]plugingetter.Checksummer{plugingetter.Checksummer{Type:"sha256", Hash:(*sha256.digest)(0xc0001b0000)}}}}
2021/07/13 16:25:52 [TRACE] Found the following "github.com/rgl/windows-update" installations: [{/home/rgl/.packer.d/plugins/github.com/rgl/windows-update/packer-plugin-windows-update_v0.12.0_x5.0_linux_amd64 v0.12.0}]
2021/07/13 16:25:52 found external [-packer-default-plugin-name-] provisioner from windows-update plugin
...
2021/07/13 16:25:53 [TRACE] Starting external plugin /home/rgl/.packer.d/plugins/github.com/rgl/windows-update/packer-plugin-windows-update_v0.12.0_x5.0_linux_amd64 start provisioner -packer-default-plugin-name-
2021/07/13 16:25:53 Starting plugin: /home/rgl/.packer.d/plugins/github.com/rgl/windows-update/packer-plugin-windows-update_v0.12.0_x5.0_linux_amd64 []string{"/home/rgl/.packer.d/plugins/github.com/rgl/windows-update/packer-plugin-windows-update_v0.12.0_x5.0_linux_amd64", "start", "provisioner", "-packer-default-plugin-name-"}
2021/07/13 16:25:53 Waiting for RPC address for: /home/rgl/.packer.d/plugins/github.com/rgl/windows-update/packer-plugin-windows-update_v0.12.0_x5.0_linux_amd64
2021/07/13 16:25:53 packer-plugin-windows-update_v0.12.0_x5.0_linux_amd64 plugin: 2021/07/13 16:25:53 Starting packer-plugin-windows-update (version 0.12.0; commit ed5cb10b6e5857c4d85747ca4aa43f07ef30c727; date 2021-04-18T21:07:09Z)
2021/07/13 16:25:53 packer-plugin-windows-update_v0.12.0_x5.0_linux_amd64 plugin: 2021/07/13 16:25:53 Plugin address: unix /tmp/packer-plugin810014715
2021/07/13 16:25:53 packer-plugin-windows-update_v0.12.0_x5.0_linux_amd64 plugin: 2021/07/13 16:25:53 Waiting for connection...
2021/07/13 16:25:53 Received unix RPC address for /home/rgl/.packer.d/plugins/github.com/rgl/windows-update/packer-plugin-windows-update_v0.12.0_x5.0_linux_amd64: addr is /tmp/packer-plugin810014715
2021/07/13 16:25:53 packer-plugin-windows-update_v0.12.0_x5.0_linux_amd64 plugin: 2021/07/13 16:25:53 Serving a plugin connection...
2021/07/13 16:25:53 packer-plugin-windows-update_v0.12.0_x5.0_linux_amd64 plugin: 2021/07/13 16:25:53 [TRACE] starting provisioner -packer-default-plugin-name-
jbpoint commented 3 years ago

packer { required_plugins { windows-update = { version = "0.12.0" source = "github.com/rgl/windows-update" } } }

i have to add this to my template file directly?

~/.packer.d/plugins/github.com/rgl/windows-update/

will add this and try again

rgl commented 3 years ago

Yes, add that snippet at the beginning of your packer template file (like in https://github.com/rgl/windows-vagrant/blob/master/windows-2019.pkr.hcl). For more information see the packer documentation at https://www.packer.io/docs/commands/init.

packer init will then download the pre-built plugin for you.

jbpoint commented 3 years ago

I was able to get the script running and via shell it finds updates, but...

as you can see in the picture below, the updates dont install. image

rgl commented 3 years ago

Why do you think they are not installing?

jbpoint commented 3 years ago

It works now. But with Windows 2016 it takes a lot of time. Any improvments?

rgl commented 3 years ago

nice! so can this issue be closed?

its normal for it to take a lot of time (4h+ here). if you could improve it, we all would appreciate :-)

jbpoint commented 3 years ago

Yes, :) we can close it. Mh, i will investigate. maybe there is a way, thank you :)