Version: 0.10.0
Host: OSX 10.11
When running the ansible-remote provisioner it is not possible to hand over --extra-vars to ansible via packer.
According to the documentation it should be as simple as:
"extra_arguments": [
"--extra-vars", "\"var1={{user `var1`}} var2={{ user `var2` }}\""
]
And now I provide the content either from within my JSON or via command line:
packer build -var "var1=foo var2=bar" "test.json"
Although packer reports that it does hand over the variables
2016/04/05 17:04:09 ui: ==> virtualbox-ovf: Executing Ansible: ansible-playbook /Users/jan/DevBase/Temp/20160405_Ansible_packer_test/site.yml -i
/var/folders/49/t4bfqy2x20qckj7cgk80xz9m0000gp/T/packer-provisioner-ansible705955031 --private-key
/var/folders/49/t4bfqy2x20qckj7cgk80xz9m0000gp/T/ansible-key398771544 --extra-vars "var1=foo
var2=bar"
it doesn't look like it is properly done, since it instantly fails as soon as it hits the first variable.
virtualbox-ovf: fatal: [127.0.0.1] => {'msg': "AnsibleUndefinedVariable: One or more undefined variables: 'var1' is undefined", 'failed': True}
I tried several other approaches (separating the vars I hand over to packer, separating the vars I hand over to ansible, JSON notation instead of key=value), however to no avail.
A full sample and the full log can be found in this gist.
Might be related to #3423.
"extra_arguments": [ "--extra-vars", "Region={{user `Region`}} Stage={{user `Stage`}}" ]
Should work
Wow, it is actually embarrassing. I paid extra attention to escaping the double quotes and never thought of dropping that, instead I check all kinds of other ways.
Thank you!
I just fell foul of this as well. Can we get the docs fixed to remove the unnecessary (and harmful) escaping of quotes?
Most helpful comment
I just fell foul of this as well. Can we get the docs fixed to remove the unnecessary (and harmful) escaping of quotes?