joefitzgerald / packer-windows

Windows Packer Templates
MIT License
1.64k stars 1.12k forks source link

chocolatey.bat failing on virtualbox-iso #109

Closed lmayorga1980 closed 8 years ago

lmayorga1980 commented 10 years ago

the following script is throwing some errors https://github.com/joefitzgerald/packer-windows/blob/master/scripts/chocolatey.bat

 virtualbox-iso: C:\Users\vagrant>powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))"  0<NUL
    virtualbox-iso: Join-Path : Cannot bind argument to parameter 'Path' because it is null.
    virtualbox-iso: At line:21 char:25
    virtualbox-iso: + $chocTempDir = Join-Path <<<<  $env:TEMP "chocolatey"
    virtualbox-iso: + CategoryInfo          : InvalidData: (:) [Join-Path], ParameterBindingVa
    virtualbox-iso: lidationException
    virtualbox-iso: + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,M
    virtualbox-iso: icrosoft.PowerShell.Commands.JoinPathCommand
    virtualbox-iso:
    virtualbox-iso: Join-Path : Cannot bind argument to parameter 'Path' because it is null.
    virtualbox-iso: At line:22 char:21
    virtualbox-iso: + $tempDir = Join-Path <<<<  $chocTempDir "chocInstall"
    virtualbox-iso: + CategoryInfo          : InvalidData: (:) [Join-Path], ParameterBindingVa
    virtualbox-iso: lidationException
    virtualbox-iso: + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,M
    virtualbox-iso: icrosoft.PowerShell.Commands.JoinPathCommand
    virtualbox-iso:
    virtualbox-iso: Exception calling "CreateDirectory" with "1" argument(s): "Path cannot be the e
    virtualbox-iso: mpty string or all whitespace."
    virtualbox-iso: At line:23 char:86
    virtualbox-iso: + if (![System.IO.Directory]::Exists($tempDir)) {[System.IO.Directory]::CreateD
    virtualbox-iso: irectory <<<< ($tempDir)}
    virtualbox-iso: + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    virtualbox-iso: + FullyQualifiedErrorId : DotNetMethodException
    virtualbox-iso:
    virtualbox-iso: Join-Path : Cannot bind argument to parameter 'Path' because it is null.
    virtualbox-iso: At line:24 char:18
    virtualbox-iso: + $file = Join-Path <<<<  $tempDir "chocolatey.zip"
    virtualbox-iso: + CategoryInfo          : InvalidData: (:) [Join-Path], ParameterBindingVa
    virtualbox-iso: lidationException
    virtualbox-iso: + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,M
    virtualbox-iso: icrosoft.PowerShell.Commands.JoinPathCommand
    virtualbox-iso:
    virtualbox-iso: Downloading http://chocolatey.org/api/v2/package/chocolatey/ to
    virtualbox-iso: Exception calling "DownloadFile" with "2" argument(s): "An exception occurred d
    virtualbox-iso: uring a WebClient request."
    virtualbox-iso: At line:34 char:27
    virtualbox-iso: +   $downloader.DownloadFile <<<< ($url, $file)
    virtualbox-iso: + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    virtualbox-iso: + FullyQualifiedErrorId : DotNetMethodException
    virtualbox-iso:
    virtualbox-iso: Download 7Zip commandline tool
    virtualbox-iso: Join-Path : Cannot bind argument to parameter 'Path' because it is null.
    virtualbox-iso: At line:42 char:20
    virtualbox-iso: + $7zaExe = Join-Path <<<<  $tempDir '7za.exe'
    virtualbox-iso: + CategoryInfo          : InvalidData: (:) [Join-Path], ParameterBindingVa
    virtualbox-iso: lidationException
    virtualbox-iso: + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,M
    virtualbox-iso: icrosoft.PowerShell.Commands.JoinPathCommand
    virtualbox-iso:
    virtualbox-iso: Downloading http://chocolatey.org/7za.exe to
    virtualbox-iso: Exception calling "DownloadFile" with "2" argument(s): "An exception occurred d
    virtualbox-iso: uring a WebClient request."
    virtualbox-iso: At line:34 char:27
    virtualbox-iso: +   $downloader.DownloadFile <<<< ($url, $file)
    virtualbox-iso: + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    virtualbox-iso: + FullyQualifiedErrorId : DotNetMethodException
    virtualbox-iso:
    virtualbox-iso: Extracting  to ...
    virtualbox-iso: Start-Process : Cannot validate argument on parameter 'FilePath'. The argument
    virtualbox-iso: is null or empty. Supply an argument that is not null or empty and then try the
    virtualbox-iso: command again.
    virtualbox-iso: At line:63 char:14
    virtualbox-iso: + Start-Process <<<<  "$7zaExe" -ArgumentList "x -o`"$tempDir`" -y `"$file`"" -
    virtualbox-iso: Wait -NoNewWindow
    virtualbox-iso: + CategoryInfo          : InvalidData: (:) [Start-Process], ParameterBindi
    virtualbox-iso: ngValidationException
    virtualbox-iso: + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power
    virtualbox-iso: Shell.Commands.StartProcessCommand
    virtualbox-iso:
    virtualbox-iso: Installing chocolatey on this machine
    virtualbox-iso: Join-Path : Cannot bind argument to parameter 'Path' because it is null.
    virtualbox-iso: At line:71 char:25
    virtualbox-iso: + $toolsFolder = Join-Path <<<<  $tempDir "tools"
    virtualbox-iso: + CategoryInfo          : InvalidData: (:) [Join-Path], ParameterBindingVa
    virtualbox-iso: lidationException
    virtualbox-iso: + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,M
    virtualbox-iso: icrosoft.PowerShell.Commands.JoinPathCommand
    virtualbox-iso:
    virtualbox-iso: Join-Path : Cannot bind argument to parameter 'Path' because it is null.
    virtualbox-iso: At line:72 char:28
    virtualbox-iso: + $chocInstallPS1 = Join-Path <<<<  $toolsFolder "chocolateyInstall.ps1"
    virtualbox-iso: + CategoryInfo          : InvalidData: (:) [Join-Path], ParameterBindingVa
    virtualbox-iso: lidationException
    virtualbox-iso: + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,M
    virtualbox-iso: icrosoft.PowerShell.Commands.JoinPathCommand
    virtualbox-iso:
    virtualbox-iso: The expression after '&' in a pipeline element produced an invalid object. It m
    virtualbox-iso: ust result in a command name, script block or CommandInfo object.
    virtualbox-iso: At line:74 char:2
    virtualbox-iso: + & <<<<  $chocInstallPS1
    virtualbox-iso: + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    virtualbox-iso: + FullyQualifiedErrorId : BadExpression
    virtualbox-iso:
    virtualbox-iso: Ensuring chocolatey commands are on the path
    virtualbox-iso:
    virtualbox-iso: C:\Users\vagrant>set /p ".=;C:\ProgramData\chocolatey\bin"  0<nul 1>>C:\Windows\Temp\PATH
    virtualbox-iso:
kensykora commented 10 years ago

This isn't a script we include in the packer runs by default, can you post your packerfile that you're using?

lmayorga1980 commented 10 years ago

@kensykora. Yeah it seems that there is an issue with the current chocolatey.bat but i am trying the .ps1 approach with the AutoUnattended.xml file.

{
    "variables": {
    "ssh_name": "vagrant",
    "ssh_pass": "vagrant",
    "puppet_release": "open",
    "puppet_version": "3.7.1",
    "iso_url": "iso/en_windows_server_2008_r2_with_sp1_vl_build_x64_dvd_617403.iso",
    "iso_checksum": "8d397b69135d207452a78c3c3051339d"
    },
    "builders": [{
    "type": "vmware-iso",
    "iso_url": "{{user `iso_url`}}",
    "iso_checksum_type": "md5",
    "iso_checksum": "{{user `iso_checksum`}}",
    "headless": false,
    "boot_wait": "2m",
    "ssh_username": "{{user `ssh_name`}}",
    "ssh_password": "{{user `ssh_pass`}}",
    "ssh_wait_timeout": "3h",
    "shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"",
    "guest_os_type": "windows7srv-64",
    "tools_upload_flavor": "windows",
    "disk_size": 61440,
    "vnc_port_min": 5900,
    "vnc_port_max": 5980,
    "floppy_files": [
    "http/cfg_windows/win2008r2/Autounattend.xml",
    "scripts/win-updates.ps1",
    "scripts/openssh.ps1",
    "scripts/oracle-cert.cer",
    "scripts/GeoTrust_Global_CA.cer"
    ],
    "vmx_data": {
    "RemoteDisplay.vnc.enabled": "false",
    "RemoteDisplay.vnc.port": "5900",
    "memsize": "2048",
    "numvcpus": "2",
    "scsi0.virtualDev": "lsisas1068"
    }
    },
    {
      "type": "parallels-iso",
      "guest_os_type": "win-2008",
      "vm_name": "parallels-windows",
      "headless": false,
      "parallels_tools_flavor": "win",
      "hard_drive_interface": "sata",
      "boot_wait": "2m",
      "disk_size":"81200",
      "iso_url": "{{user `iso_url`}}",
      "iso_checksum": "{{user `iso_checksum`}}",
      "iso_checksum_type": "md5",
      "ssh_username": "{{user `ssh_name`}}",
      "ssh_password": "{{user `ssh_pass`}}",
      "ssh_wait_timeout": "4h",
      "floppy_files": [
      "http/cfg_windows/win2008r2/Autounattend.xml",
      "scripts/microsoft-updates.bat",
      "scripts/win-updates.ps1",
      "scripts/openssh.ps1",
      "scripts/oracle-cert.cer",
      "scripts/GeoTrust_Global_CA.cer"
       ],
      "shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"",
      "prlctl": [
       ["set", "{{.Name}}", "--memsize", "2048"],
       ["set", "{{.Name}}", "--cpus", "2"],
       ["set", "{{.Name}}", "--winsystray-in-macmenu","off"],
       ["set", "{{.Name}}", "--startup-view", "window"]
       ]
    },
    {
    "type": "virtualbox-iso",
    "iso_url": "{{user `iso_url`}}",
    "iso_checksum_type": "md5",
    "iso_checksum": "{{user `iso_checksum`}}",
    "headless": false,
    "boot_wait": "2m",
    "ssh_username": "{{user `ssh_name`}}",
    "ssh_password": "{{user `ssh_pass`}}",
    "ssh_wait_timeout": "3h",
    "disk_size": 61440,
    "shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"",
    "guest_os_type": "Windows2008_64",
    "floppy_files": [
    "http/cfg_windows/win2008r2/Autounattend.xml",
    "scripts/win-updates.ps1",
    "scripts/openssh.ps1",
    "scripts/oracle-cert.cer",
    "scripts/chocolatey.bat",
    "scripts/GeoTrust_Global_CA.cer"
    ],
    "vboxmanage": [
    ["modifyvm", "{{.Name}}", "--memory", "2048"],
    ["modifyvm", "{{.Name}}", "--cpus", "2"]
    ]
    },
    {
    "type": "amazon-ebs",
    "region": "us-east-1",
    "source_ami": "ami-6a38cc02",
    "instance_type": "t1.micro",
    "ssh_username": "vagrant",
    "ssh_private_key_file": "/Users/lmo0/.ssh/id_vagrant",
    "ami_name": "packer-quick-start {{timestamp}}",
    "tags": {
      "OS_Version": "Windows",
      "Release": "2008R2"
     }
     }
    ],
    "provisioners": [{
    "type": "shell",
    "environment_vars": [ "PUPPET_RELEASE={{user `puppet_release`}}",
                        "PUPPET_VERSION={{user `puppet_version`}}"
                        ],
    "remote_path": "/tmp/script.bat",
    "execute_command": "{{.Vars}} cmd /c C:/Windows/Temp/script.bat",
    "scripts": [
    "./scripts/vm-guest-tools.bat",
    "./scripts/vagrant-ssh.bat",
    "./scripts/provisioners.bat"
    ]
    },
    { "type": "shell", "inline": ["rm -rf /tmp/*"] }
    ],
    "post-processors": [{
    "type": "vagrant",
    "keep_input_artifact": false,
    "output": "win2008r2-{{user `puppet_release`}}-{{user `puppet_version`}}-{{.Provider}}.box",
    "vagrantfile_template": "vagrant-templates/vagrantfile-windows_2008_r2.template"
    }]
}
dylanmei commented 10 years ago

Like many of the original scripts, chocolatey.bat is authored to run from scripts, which is much further downstream than Autounattended. My understanding is that Autounattend resources are items that everyone should run all the time, and scripts are a buffet of items we could add and remove to suit our needs. This meant that, in general, a person didn't have to edit the xml but simply tailor the Packer template.

IIRC Chocolatey relies on user env variables which, if not set, will make the whole thing fall over.

ferventcoder commented 10 years ago

Ugh. Relies means a bug.

lmayorga1980 commented 9 years ago

@dylanmei Agree with you on the Autounattended.

{
    "variables": {
    "ssh_name": "vagrant",
    "ssh_pass": "vagrant",
    "puppet_release": "open",
    "puppet_version": "1.0.0",
    "iso_url": "iso/en_windows_server_2008_r2_with_sp1_vl_build_x64_dvd_617403.iso",
    "iso_checksum": "8d397b69135d207452a78c3c3051339d"
    },
    "builders": [{
    "type": "vmware-iso",
    "iso_url": "{{user `iso_url`}}",
    "iso_checksum_type": "md5",
    "iso_checksum": "{{user `iso_checksum`}}",
    "headless": false,
    "boot_wait": "2m",
    "ssh_username": "{{user `ssh_name`}}",
    "ssh_password": "{{user `ssh_pass`}}",
    "ssh_wait_timeout": "3h",
    "shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"",
    "guest_os_type": "windows7srv-64",
    "tools_upload_flavor": "windows",
    "disk_size": 61440,
    "vnc_port_min": 5900,
    "vnc_port_max": 5980,
    "floppy_files": [
    "http/cfg_windows/win2008r2/Autounattend.xml",
    "scripts/win-updates.ps1",
    "scripts/openssh.ps1",
    "scripts/oracle-cert.cer",
    "scripts/GeoTrust_Global_CA.cer"
    ],
    "vmx_data": {
    "RemoteDisplay.vnc.enabled": "false",
    "RemoteDisplay.vnc.port": "5900",
    "memsize": "2048",
    "numvcpus": "2",
    "scsi0.virtualDev": "lsisas1068"
    }
    },
    {
      "type": "parallels-iso",
      "guest_os_type": "win-2008",
      "vm_name": "parallels-windows",
      "headless": false,
      "parallels_tools_flavor": "win",
      "hard_drive_interface": "sata",
      "boot_wait": "2m",
      "disk_size":"81200",
      "iso_url": "{{user `iso_url`}}",
      "iso_checksum": "{{user `iso_checksum`}}",
      "iso_checksum_type": "md5",
      "ssh_username": "{{user `ssh_name`}}",
      "ssh_password": "{{user `ssh_pass`}}",
      "ssh_wait_timeout": "4h",
      "floppy_files": [
      "http/cfg_windows/win2008r2/Autounattend.xml",
      "scripts/microsoft-updates.bat",
      "scripts/win-updates.ps1",
      "scripts/openssh.ps1",
      "scripts/oracle-cert.cer",
      "scripts/GeoTrust_Global_CA.cer"
       ],
      "shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"",
      "prlctl": [
       ["set", "{{.Name}}", "--memsize", "2048"],
       ["set", "{{.Name}}", "--cpus", "2"],
       ["set", "{{.Name}}", "--winsystray-in-macmenu","off"],
       ["set", "{{.Name}}", "--startup-view", "window"]
       ]
    },
    {
    "type": "virtualbox-iso",
    "iso_url": "{{user `iso_url`}}",
    "iso_checksum_type": "md5",
    "iso_checksum": "{{user `iso_checksum`}}",
    "headless": false,
    "boot_wait": "2m",
    "ssh_username": "{{user `ssh_name`}}",
    "ssh_password": "{{user `ssh_pass`}}",
    "ssh_wait_timeout": "3h",
    "disk_size": 61440,
    "shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"",
    "guest_os_type": "Windows2008_64",
    "floppy_files": [
    "http/cfg_windows/win2008r2/Autounattend.xml",
    "scripts/win-updates.ps1",
    "scripts/openssh.ps1",
    "scripts/oracle-cert.cer",
    "scripts/GeoTrust_Global_CA.cer"
    ],
    "vboxmanage": [
    ["modifyvm", "{{.Name}}", "--memory", "2048"],
    ["modifyvm", "{{.Name}}", "--cpus", "2"]
    ]
    },
    {
    "type": "amazon-ebs",
    "region": "us-east-1",
    "source_ami": "ami-6a38cc02",
    "instance_type": "t1.micro",
    "ssh_username": "vagrant",
    "ssh_private_key_file": "/Users/lmo0/.ssh/id_vagrant",
    "ami_name": "packer-quick-start {{timestamp}}",
    "tags": {
      "OS_Version": "Windows",
      "Release": "2008R2"
     }
     }
    ],
    "provisioners": [{
    "type": "shell",
    "environment_vars": [ "PUPPET_RELEASE={{user `puppet_release`}}",
                        "PUPPET_VERSION={{user `puppet_version`}}"
                        ],
    "remote_path": "/tmp/script.bat",
    "execute_command": "{{.Vars}} cmd /c C:/Windows/Temp/script.bat",
    "scripts": [
    "./scripts/vm-guest-tools.bat",
    "./scripts/vagrant-ssh.bat",
    "./scripts/enable-rdp.bat",
    "./scripts/compile-dotnet-assemblies.bat",
    "./scripts/compact.bat",
    "./scripts/provisioners.bat",
    "./scripts/chocolatey.bat"
    ]
    },
    { "type": "shell", "inline": ["rm -rf /tmp/*"] }
    ],
    "post-processors": [{
    "type": "vagrant",
    "keep_input_artifact": false,
    "output": "win2008r2-{{user `puppet_release`}}-{{user `puppet_version`}}-{{.Provider}}.box",
    "vagrantfile_template": "vagrant-templates/vagrantfile-windows_2008_r2.template"
    }]
}

chocolatey.bat

powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" <NUL

<nul set /p ".=;%ALLUSERSPROFILE%\chocolatey\bin" >> C:\Windows\Temp\PATH
set /p PATH=<C:\Windows\Temp\PATH
setx PATH "%PATH%" /m

It seems like chocolatey hangs installing NetFx 4.0

ferventcoder commented 9 years ago

@dylanmei choco should no longer rely on environment variables like temp. If they are not there it uses a different var.

@lmayorga1980 Sounds like new choco is having issues installing - can you verify that the batch appends -y to the other choco install commands as well?

lmayorga1980 commented 9 years ago

@ferventcoder you mean this guy

https://github.com/chocolatey/choco/blob/ce90c21acebc44f74b21df2a096cb2b3504c0851/nuget/chocolatey/tools/chocolateysetup.psm1#L450-L500?

I guess chocolatey detected that NetFx4.0 was not there and it tried to installed and it just hangs. Trying again

ferventcoder commented 9 years ago

@lmayorga1980 not sure how good the internet connection is, but it is going to try to download a 45 MB file from the nets.

If you bundle in the NetFx file based on $tempDir:

sneal commented 8 years ago

This looks like its been "fixed" in the upstream choco script, and if its not... Its probably because OpenSSH isn't properly setting env vars so once we switch over to WinRM this will definitely be addressed.