Pass arguments to Script powershell provisioner

196 views
Skip to first unread message

goffries

unread,
Oct 4, 2018, 6:57:31 PM10/4/18
to Packer
Is there a way to pass arguments to a script using the powershell provisioner without using Inline?

example.

        {
            "type": "powershell",
            "script": "D:\\Scripts\\windows-vscodeinstall.ps1  -version {{user `version` }}"
        }

Rickard von Essen

unread,
Oct 5, 2018, 3:59:06 AM10/5/18
to packe...@googlegroups.com
You can modify 1) execute_command to pass arguments, but a better way is to pass information via environemnt_vars 2) because then you can run all you scripts in the same powershell provisioner.


--
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 packer-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/dd57eb14-bcc6-403f-84e5-14ce22eae468%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

goffries

unread,
Oct 5, 2018, 1:54:06 PM10/5/18
to Packer
Thank you for the reply! You wouldn't happen to have a couple examples of templates/scripts that use the environment vars in the way you describe, would you?

federico montaldo

unread,
Oct 5, 2018, 4:24:15 PM10/5/18
to packe...@googlegroups.com
Hi,

I got the same cocern becase I need to install a custon windows 10 vm
with the following:

Windows 10

.NET 4.7.2

.NET Core 2.x

Visual Studio Community 2017

I think the first two I can install it wiht chocolatey. This is my
packer template.

{

"builders": [

{

"type": "virtualbox-iso",

"iso_url": "{{user `iso_url`}}",

"iso_checksum_type": "{{user `iso_checksum_type`}}",

"iso_checksum": "{{user `iso_checksum`}}",

"headless": false,

"guest_additions_mode": "attach",

"boot_wait": "2m",

"communicator": "winrm",

"winrm_username": "vagrant",

"winrm_password": "vagrant",

"winrm_timeout": "5h",

"shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer
Shutdown\"",

"shutdown_timeout": "15m",

"guest_os_type": "Windows81_64",

"disk_size": 61440,

"floppy_files": [

"{{user `autounattend`}}",

"{{user `autounattend`}}",

"./floppy/WindowsPowershell.lnk",

"./floppy/PinTo10.exe",

"./scripts/fixnetwork.ps1",

"./scripts/disable-screensaver.ps1",

"./scripts/disable-winrm.ps1",

"./scripts/enable-winrm.ps1",

"./scripts/microsoft-updates.bat",

"./scripts/win-updates.ps1",

],

"vboxmanage": [

[

"modifyvm",

"{{.Name}}",

"--memory",

"2048"

],

[

"modifyvm",

"{{.Name}}",

"--cpus",

"2"

]

]

}

],

"provisioners": [

{

"scripts": [

"./scripts/docker/10/install-containers-feature.ps1"

],

"type": "powershell"

},

{

"type": "windows-restart"

},

{

"environment_vars": [

"docker_images={{user `docker_images`}}",

"docker_provider={{user `docker_provider`}}",

"docker_version={{user `docker_version`}}"

],

"scripts": [

"./scripts/docker/add-docker-group.ps1",

"./scripts/docker/install-docker.ps1",

"./scripts/docker/docker-pull.ps1",

"./scripts/docker/open-docker-insecure-port.ps1",

"./scripts/docker/open-docker-swarm-ports.ps1",

"./scripts/docker/remove-docker-key-json.ps1",

"./scripts/docker/disable-windows-defender.ps1"

],

"type": "powershell"

},

{

"scripts": [

"./scripts/uac-enable.bat",

"./scripts/set-winrm-automatic.bat",

"./scripts/compact.bat"

],

"type": "windows-shell"

}

],

"post-processors": [

{

"type": "vagrant",

"keep_input_artifact": false,

"output": "windows_10_docker{{.Provider}}.box",

"vagrantfile_template": "vagrantfile-windows_10.template"

}

],

"variables": {



"iso_url": "https://software-download.microsoft.com/download/pr/17134.1.180410-1804.rs4_release_CLIENTENTERPRISEEVAL_OEMRET_x64FRE_en-us.iso",

"iso_checksum_type": "md5",

"iso_checksum": "89f6b3079b3669560d29f3c4be9cc74d",

"autounattend": "./answer_files/10/Autounattend.xml"

}

}

In which path should I cinlude the script to install visual studio and
the other features?. This is an example of the visual studio script:

$vs2017Url = "https://aka.ms/vs/15/release/vs_community.exe";
$vs2017Exe = "${env:Temp}\vs_community.exe";
Invoke-WebRequest -Uri $vs2017Url -OutFile $vs2017Exe;
cd ${env:Temp}
.\vs_community.exe --add Microsoft.VisualStudio.Workload.Azure
--includeRecommended --includeOptional --quiet --norestart

And the last question. There is a way to include docker containers in
the build?. I got the follwoing example:

"variables": {
"docker_images": "microsoft/windowsservercore microsoft/nanoserver",
"docker_provider": "ce",
"docker_version": "17.10.0",
"source_path": "path-to.vmx"
}
}

Regards
> To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/fcafcfdd-09c9-4094-bb29-ef9d1b2cd351%40googlegroups.com.

Rickard von Essen

unread,
Oct 5, 2018, 4:36:39 PM10/5/18
to packe...@googlegroups.com
Unfortunately not, I'm more of a Unix person. Hopefully someone else on the list can help. 

Rickard von Essen

unread,
Oct 6, 2018, 2:09:22 AM10/6/18
to packe...@googlegroups.com
Couldn't fin any Windows examples, but here is one for Linux:


On Fri, Oct 5, 2018, 19:54 goffries <goff...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages