I want to take the HTTP address that packer creates and pass that to 
Powershell for downloading a file (Invoke-WebRequest cmdlet).

How do I do it?

I've tried all different combinations of:

{
  "variables": {
    "http_addr": "{{ env `PACKER_HTTP_ADDR` }}"
  },
  "builders": [
    {
      "type": "vmware-iso",
      "vmx_data": {
        "tools.upgrade.policy": "manual",
        "virtualhw.productcompatibility" : "hosted",
        "vcpu.hotadd": "TRUE",
        "mem.hotadd": "TRUE",
        "tools.syncTime": "FALSE",
        "gui.applyHostDisplayScalingToGuest": "FALSE"
      },
      "guest_os_type": "windows9srv-64",
      "iso_urls": [
        "C:\\ISOs\\en_windows_server_2016_vl_x64_dvd_11636701.iso",
        "ISOs/en_windows_server_2016_vl_x64_dvd_11636701.iso"
      ],
      "iso_checksum": "186F55D26F4E9B60F8616B5485080A30BABA6F82",
      "iso_checksum_type": "sha1",
      "vm_name": "Windows2016",
      "vmdk_name": "Windows2016",
      "headless": "true",
      "skip_compaction": "true",
      "communicator": "winrm",
      "winrm_username": "Administrator",
      "winrm_password": "MYPASSWORDHERE",
      "winrm_port": "5985",
      "winrm_use_ssl": "false",
      "winrm_timeout": "5h",
      "winrm_insecure": "true",
      "shutdown_command": "C:/Windows/Temp/packershutdown.bat",
      "shutdown_timeout": "15m",
      "network_adapter_type": "vmxnet3",
      "disk_adapter_type": "pvscsi",
      "disk_type_id": "0",
      "disk_size": "66560",
      "disk_additional_size": "30720",
      "http_directory": "installs/",
      "http_port_min": "8000",
      "http_port_max": "8000",
      "cpus": "2",
      "memory": "4096",
      "version": "11",
      "vmx_remove_ethernet_interfaces": "true",
      "vmx_data_post": {
        "virtualhw.productcompatibility": "",
        "nvram": ""
      },
      "floppy_files": [
        "answer_files/2016/Autounattend.xml",
        "drivers/pvscsi",
        "drivers/vmxnet3",
        "scripts/enable-winrm.ps1"
      ]
    }
  ],
  "provisioners": [
    {
      "type": "powershell",
      "elevated_user": "Administrator",
      "elevated_password": "MYPASSWORDHERE",
      "inline": [
        "if (!(test-path C:\\Utilities\\)) {mkdir C:\\Utilities\\}"
      ]
    },
    {
      "environment_vars": [
        "http_addr={{ user `http_addr` }}"
      ],
      "type": "powershell",
      "elevated_user": "Administrator",
      "elevated_password": "MYPASSWORDHERE",
      "inline": [
        "Invoke-WebRequest $Env:http_addr/MyUtil.exe -OutFile 
C:\\Utilities\\MyUtil.exe"
      ]
    }
  ]
}


-- 
This mailing list is governed under the HashiCorp Community Guidelines - 
https://www.hashicorp.com/community-guidelines.html. Behavior in violation of 
those guidelines may result in your removal from this mailing list.

GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
--- 
You received this message because you are subscribed to the Google Groups 
"Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/packer-tool/af6f0480-7cef-4da4-80a3-72aafa03212a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to