New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Env
variables are not being set for remote shell provisioners
#11670
Comments
Confirmed the same for *nix shells as well. |
As mentioned in issue #11670, the Shell provider did not support Env variable declarations in the HCL templates. This commit adds the capability to the code.
As mentioned in issue #11670, the Shell provider did not support Env variable declarations in the HCL templates. This commit adds the capability to the code.
* provisioner/shell: add support for Env variables As mentioned in issue #11670, the Shell provider did not support Env variable declarations in the HCL templates. This commit adds the capability to the code. * provisioner/powershell: add support for Env vars * provisioner/windows-shell: support Env variables
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Overview of the Issue
Usage of
env
option with shell provisioners was added: #11569. This works when using theshell-local
provisioner but with remote shell provisioners the variables are not being set and no error is being thrown. Only variables defined inenvironment_vars
are being set so it appears thatenv
values are being ignored for these provisioners. I'm presuming that all the shell provisioners should be able to work with thisenv
option because all of their docs were updated to reference it...but maybe this wasn't the intention?Reproduction Steps
windows-shell
orpowershell
provisioner.env
option.Packer version
Simplified Packer Template
Output
Workaround
I'm not an expert but it looks like the problem might be with this
createFlattenedEnvVars
method defined in https://github.com/hashicorp/packer-plugin-sdk/blob/f7d4bf877a45a9d253c548e902d6d1bd7d907d23/shell-local/run.go#L174. While theshell-local
provisioner appears to use this method as is, thewindows-shell
, andpowershell
(and evenshell
) provisioners appear to redefine it and do custom things.The important bit seems to be this change here: https://github.com/hashicorp/packer-plugin-sdk/blob/f7d4bf877a45a9d253c548e902d6d1bd7d907d23/shell-local/run.go#L209 that was made only in the SDK and not in the other provisioners. So, as a test I add this to the
powershell
provisioner and it seemed to fix itOperating system and Environment details
Windows 11 build 10.0.22000.0 x64
Target OS: Windows Server 2019
Powershell v7.2.1
The text was updated successfully, but these errors were encountered: