PACKER_BUILDER_TYPE is not set in PowerShell and WindowsShell provisioner

475 views
Skip to first unread message

Gergely Brautigam

unread,
Jul 1, 2015, 10:34:44 AM7/1/15
to packe...@googlegroups.com
Hey Guys.

I'm surly missing something I need to set here. I know that the regular shell provisioner, when running on windows uses {{ .Vars }} and that sets up stuff.

But when I started using WindowsShell and PowerShell like this :=

  "provisioners": [
    {
      "type": "windows-shell",
      "scripts": [
        "./scripts/vm-guest-tools.bat",
        "./scripts/puppet.bat",
        "./scripts/vagrant-ssh.bat",
        "./scripts/rsync.bat",
        "./scripts/enable-rdp.bat"
      ]
    },{
      "type": "powershell",
      "scripts": [
        "./scripts/jdk_inst.ps1",
        "./scripts/office_2007_inst.ps1"
      ]
    }
  ],

... when vm-guest-tools runs or, the powershell stuff begins to execute, it sees PACKER_BUILDER_TYPE as Empty. "".

I'm guessing it's not set, or not passed in. How do I do that with these two?

I could use something like this:

PACKER_BUILDER_TYPE=virtualbox-iso in the appropriate provisioner phase, but I read that this should be set automatically. No?

Cheers,
Gergely

Gergely Brautigam

unread,
Jul 1, 2015, 10:49:45 AM7/1/15
to packe...@googlegroups.com
I tried to do this =>
        "environment_vars": [
            "PACKER_BUILDER_TYPE=virtualbox-iso"
        ]

But it did not work.

Gergely Brautigam

unread,
Jul 1, 2015, 10:52:22 AM7/1/15
to packe...@googlegroups.com
And then I'm getting all sorts of interesting stuff from PowerShell since PACKER_BUILDER_TYPE is not set, I'm guessing:

The term ':PACKER_BUILDER_TYPE=virtualbox-iso' is not recognized as the name of
1435762233,,ui,message,    virtualbox-iso: a cmdlet%!(PACKER_COMMA) function%!(PACKER_COMMA) script file%!(PACKER_COMMA) or operable program. Check the spelling of th
1435762233,,ui,message,    virtualbox-iso: e name%!(PACKER_COMMA) or if a path was included%!(PACKER_COMMA) verify that the path is correct and try agai
1435762233,,ui,message,    virtualbox-iso: n.
1435762233,,ui,message,    virtualbox-iso: At line:1 char:42

Alvaro Miranda Aguilera

unread,
Jul 1, 2015, 5:25:05 PM7/1/15
to packe...@googlegroups.com
Hello Gergely

I am not a Packer+Windows person, but I do use packer.

all the variables should be inside {{ .Vars }}

On the linux side if I require to have the variables that packer
create in the shell for the provisioner, this is one way of doing it:

{
"type": "shell",
"execute_command": "echo 'vagrant'| {{ .Vars }} sudo -E -S bash
'{{.Path}}'",
"pause_before": "1s",
"inline": [
"[ -f /root/proxy.env ] && source /root/proxy.env",
"yum update -y",
"yum localinstall -y
http://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm",
"yum-config-manager --disable epel",
"reboot"
]
},


The execute_command basically will be transformed as:

var1=key1 var2=key2 sudo -E -S bash /tmp/script1


On windows, check that this person does here:

https://github.com/joefitzgerald/packer-windows/blob/330b09c9a4565918b1028218532979112da55a0f/windows_2008_r2.json#L69-L80


{
"type": "shell",
"remote_path": "/tmp/script.bat",
"execute_command": "{{.Vars}} cmd /c C:/Windows/Temp/script.bat",
"scripts": [
"./scripts/vm-guest-tools.bat",
"./scripts/chef.bat",
"./scripts/vagrant-ssh.bat",
"./scripts/enable-rdp.bat",
"./scripts/disable-auto-logon.bat",
"./scripts/compact.bat"
]
},

Seems you can use the same idea for Windows

hope this helps
> --
> 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/74a5e79d-0710-41f6-8055-55319ca8797b%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

Gergely Brautigam

unread,
Jul 2, 2015, 1:12:22 AM7/2/15
to packe...@googlegroups.com
Hello Alvaro.

Yeah, I know about execute command, but actually I didn't realise that it doesn't have to be an actual script it tries to run its just runs it to inject environment variables. Now everything makes sense after I saw what you are doing on Linux. I'm a Linux person as well so windows is a very new area for me (hating it already :P).

Thanks very much!

Gergely Brautigam

unread,
Jul 2, 2015, 4:14:57 AM7/2/15
to packe...@googlegroups.com
Tested this. It did not work with PowerShell or WindowsShell, but it works with simple Shell provisioning. I'm gonna submit an issue about that.

Thanks!
Gergely.

Alvaro Miranda Aguilera

unread,
Jul 2, 2015, 5:45:54 PM7/2/15
to packe...@googlegroups.com
Yeah, for PowerShell out of the box it should work:

documenation state:

environment_vars (array of strings) - An array of key/value pairs to
inject prior to the execute_command. The format should be key=value.
Packer injects some environmental variables by default into the
environment, as well, which are covered in the section below.

execute_command (string) - The command to use to execute the script.
By default this is powershell "& { {{.Vars}}{{.Path}}; exit
$LastExitCode}". The value of this is treated as configuration
template. There are two available variables: Path, which is the path
to the script to run, and Vars, which is the list of environment_vars,
if configured.


Can you share a sample reproductable case in the bug? that will help
the review of the same.

Thanks!
Alvaro.
> --
> 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/26838830-1ba6-492d-b48a-987302eb27e8%40googlegroups.com.

Gergely Brautigam

unread,
Jul 3, 2015, 6:44:51 AM7/3/15
to packe...@googlegroups.com
On Thursday, 2 July 2015 23:45:54 UTC+2, Alvaro Miranda Aguilera wrote:
Yeah, for PowerShell out of the box it should work:

documenation state:

environment_vars (array of strings) - An array of key/value pairs to
inject prior to the execute_command. The format should be key=value.
Packer injects some environmental variables by default into the
environment, as well, which are covered in the section below.

execute_command (string) - The command to use to execute the script.
By default this is powershell "& { {{.Vars}}{{.Path}}; exit
$LastExitCode}". The value of this is treated as configuration
template. There are two available variables: Path, which is the path
to the script to run, and Vars, which is the list of environment_vars,
if configured.


Can you share a sample reproductable case in the bug? that will help
the review of the same.

Ofc. Did that. Here is the created issue => https://github.com/mitchellh/packer/issues/2378

Cheers,
Gergely.
 
Reply all
Reply to author
Forward
0 new messages