Merge pull request #5869 from Daemoen/bugfix-5852

Bugfix 5852
This commit is contained in:
Matthew Hooker 2018-02-07 19:57:09 -08:00 committed by GitHub
commit 84190acec7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -327,7 +327,11 @@ func (p *Provisioner) executeAnsible(ui packer.Ui, comm packer.Communicator, pri
p.config.PackerBuildName, p.config.PackerBuilderType),
"-i", inventory, playbook}
if len(privKeyFile) > 0 {
args = append(args, "--private-key", privKeyFile)
// Changed this from using --private-key to supplying -e ansible_ssh_private_key_file as the latter
// is treated as a highest priority variable, and thus prevents overriding by dynamic variables
// as seen in #5852
// args = append(args, "--private-key", privKeyFile)
args = append(args, "-e", fmt.Sprintf("ansible_ssh_private_key_file=%s", privKeyFile))
}
args = append(args, p.config.ExtraArguments...)
if len(p.config.AnsibleEnvVars) > 0 {