From 5d67f77f4325b7c9922e72170f52030fa9dfade0 Mon Sep 17 00:00:00 2001 From: Marc Mercer Date: Wed, 7 Feb 2018 19:41:01 -0800 Subject: [PATCH 1/2] Fixing 5852 --- provisioner/ansible/provisioner.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/provisioner/ansible/provisioner.go b/provisioner/ansible/provisioner.go index 18965d220..4992b532c 100644 --- a/provisioner/ansible/provisioner.go +++ b/provisioner/ansible/provisioner.go @@ -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 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 { From d3c7d43f20236706414c735012280e72baf38223 Mon Sep 17 00:00:00 2001 From: Marc Mercer Date: Wed, 7 Feb 2018 19:47:01 -0800 Subject: [PATCH 2/2] Small typo correction --- provisioner/ansible/provisioner.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/provisioner/ansible/provisioner.go b/provisioner/ansible/provisioner.go index 4992b532c..2984e496a 100644 --- a/provisioner/ansible/provisioner.go +++ b/provisioner/ansible/provisioner.go @@ -327,7 +327,7 @@ func (p *Provisioner) executeAnsible(ui packer.Ui, comm packer.Communicator, pri p.config.PackerBuildName, p.config.PackerBuilderType), "-i", inventory, playbook} if len(privKeyFile) > 0 { - // Changed this from using --private-key to supplying -e ansible_ssh_private_key as the latter + // 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)