When using the googlecompute builder in packer 1.5.4 the {{.WinRMPassword}} does not contain any data in the provisioners stages. This cases an issue when trying to execute ansible-playbook from a shell-local provisioner as you don't know what the WinRM password has been set too.
This problem does not happen older versions of packer e.g. 1.4.5.
Run packer build template.json
template.json contains the following:
{
"builders": [
{
"type": "googlecompute",
"account_file": "account.json",
"project_id": "packer-gcp",
"source_image": "windows-server-2019-dc-v20200211",
"communicator": "winrm",
"disk_size": "50",
"winrm_username": "packer_user",
"winrm_insecure": true,
"winrm_use_ssl": true,
"ssh_username": "packer",
"zone": "europe-west2-a",
"metadata": {
"windows-startup-script-cmd": "winrm set winrm/config/service/auth @{Basic=\"true\"}"
}
}
],
"provisioners": [
{
"type": "shell-local",
"command": "echo {{.WinRMPassword}}"
}
]
}
The shell output for WinRMPassword will be blank in packer 1.5.4 but in 1.4.5 it will contain the correctly generated password.
From 1.5.4
This is the case when running packer from both a Windows and Linux environment.
Have just performed some further testing and this appears to be an issue from version 1.5.0 onwards.
Hi @tmmruk in version 1.5.0 a new build engine was introduced for sharing dynamic variables (created and populated during build time) with provisioners. If you update your provisioner to use the new build engine is the value still empty?
{{build `WinRMPassword`}}
Hi @nywilken. I wasn't aware of that change, however, I've just tested it and it looks to have the same problem. I would have thought it would be best to support {{.WinRMPassword}} for backwards compatibilty anyway.
Hi @tmmruk thanks for testing with the build engine. We'll take a look to see what might be happening here as soon as we have a chance.
Sorry for this! This was an accidental regression, not an intentional backwards incompatibility. I've just pushed a fix that brings the googlecompute builder in line with the others. Any of the following examples should correctly interpolate now:
"provisioners": [
{
"type": "shell-local",
"inline": [
"echo '{{ build `Password`}}'",
"echo '{{ build `WinRMPassword`}}'",
"echo '{{ .WinRMPassword}}'"
]
}
It will be released in the 1.5.5 release, but if you don't want to wait you can download binaries built from the linked PR here: https://circleci.com/gh/hashicorp/packer/38835#artifacts/containers/0
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.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Most helpful comment
Sorry for this! This was an accidental regression, not an intentional backwards incompatibility. I've just pushed a fix that brings the googlecompute builder in line with the others. Any of the following examples should correctly interpolate now:
It will be released in the 1.5.5 release, but if you don't want to wait you can download binaries built from the linked PR here: https://circleci.com/gh/hashicorp/packer/38835#artifacts/containers/0