hashicorp / packer-plugin-ansible

Packer plugin for Ansible Provisioner
https://www.packer.io/docs/provisioners/ansible
Mozilla Public License 2.0
50 stars 36 forks source link

Fix quoting of arguments passed through ansible_ssh_extra_args #169

Closed Jackenmen closed 1 year ago

Jackenmen commented 1 year ago

Fixes #158 by quoting individual arguments in the ansible_ssh_extra_args list instead of joining arguments and only quoting all of them together after.

Note that I kept the simple implementation of only putting arguments in quotes but ideally, you'd probably want to consider using a dedicated library for joining arguments using sh's word-splitting rules such as go-shellquote.

Recreated from #168 because I used the wrong account, sorry about the spam...

hashicorp-cla commented 1 year ago

CLA assistant check
All committers have signed the CLA.

Jackenmen commented 1 year ago

Actually, the behavior of one-string workaround stays the same with this change - since there's only item in the list, Join that I added doesn't do anything in such a case. So using older plugin version for that shouldn't be needed.

On the other hand, the behavior of passing multiple extra arguments as actual separate items in the list (which is the intended way of using this plugin argument) may be different between Ansible 8+ and Ansible <8 which has to do with those versions behaving different with quote handling. I can't recall what the difference was though so you might want to test this before documenting :)

lbajolet-hashicorp commented 1 year ago

Oh yeah fair, those having one string only won't have an issue, but yeah I would not give guarantees that this change will work on versions of Ansible <8.

Come to think of it, this may be better pointed out in the release notes for the next version of the plugin (we'll probably release it by the end of the week), if later we see users having trouble with this, we'll amend the docs.