different behavior for powershell templatefile script launched through inline or scripts
- Dominant language
- Go
- Stars
- 15.8k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
When filing a bug, please include the following headings if possible. Any
example text in this template can be deleted.
#### Overview of the Issue
I was trying to use a script ( with provisioner "powershell" and 'scripts' = ) created from a templatefile and copied to a cdrom with cd_content. The variables were correctly set in the resulting file, but the execution acted like they did not.
Using the exact same script with 'inline' works flawlessly.
### Packer version
1.7.10
#### Reproduction Steps
Create a windows VM with vsphere-iso and add in files the code below.
### Simplified Packer Template
- scripts/bug.ps1
```powershell
$foo = "${foo}"
echo "the value of foo is $foo"
```
- main.pkr.hcl
```
cd_content = {
"bug.ps1" = templatefile("scripts/bug.ps1", {
foo = var.foo
}
)
}
```
```
provisioner "powershell" {
scripts = ["scripts/bug.ps1"]
}
```
```
provisioner "powershell" {
inline = [templatefile("scripts/bug.ps1", {
foo = var.foo
})]
}
```
- variables.pkr.hcl
```
variable "foo" {
type = string
default = "bar"
}
```
### Operating system and Environment details
Gentoo
Bash
### Log Fragments and crash.log files
==> vsphere-iso.windows: Provisioning with powershell script: scripts/bug.ps1
vsphere-iso.windows: the value of foo is
==> vsphere-iso.windows: Provisioning with Powershell...
==> vsphere-iso.windows: Provisioning with powershell script: /tmp/powershell-provisioner1274727291
vsphere-iso.windows: the value of foo is bar
Note that in the first call (scripts) , the value is not printed, while it is in the second one (inline).
The odd thing is that the script is correct on the remote machine ie:
```
$foo = "bar"
echo "the value of foo is $foo"
```
and works fine if manually executed.
Contributor guide
Assessment
This issue has not been assessed yet.