Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

synchronize: quotes around arguments #213

Merged
merged 3 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelogs/fragments/213_quote_cmd_args.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
bugfixes:
- Synchronize module not recognizing remote ssh key (https://github.com/ansible-collections/ansible.posix/issues/24).
- Synchronize not using quotes around arguments like --out-format (https://github.com/ansible-collections/ansible.posix/issues/190).
10 changes: 5 additions & 5 deletions plugins/modules/synchronize.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,10 +548,10 @@ def main():
ssh_cmd_str = ' '.join(shlex_quote(arg) for arg in ssh_cmd)
if ssh_args:
ssh_cmd_str += ' %s' % ssh_args
cmd.append('--rsh=%s' % ssh_cmd_str)
cmd.append(shlex_quote('--rsh=%s' % ssh_cmd_str))

if rsync_path:
cmd.append('--rsync-path=%s' % rsync_path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to add tests for this change?

Copy link
Contributor Author

@flybyray flybyray Jul 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a test for it.
https://github.com/ansible-collections/ansible.posix/blob/main/tests/integration/targets/synchronize/tasks/main.yml#L154-L166

As @quidame mentioned later the integration tests were disabled sometime ago. I now enabled them. localy with docker it worked

TASK [synchronize : synchronize files using rsync_path (issue#7182)] ***********
changed: [testhost] => {"changed": true, "cmd": "/usr/bin/rsync --delay-updates -F --compress --archive '--rsync-path=sudo rsync' '--out-format=<<CHANGED>>%i %n%L' /root/ansible_collections/ansible/posix/tests/output/.tmp/output_dir/foo.txt /root/ansible_collections/ansible/posix/tests/output/.tmp/output_dir/foo.rsync_path", "msg": ">f+++++++++ foo.txt\n", "rc": 0, "stdout_lines": [">f+++++++++ foo.txt"]}

TASK [synchronize : assert] ****************************************************
ok: [testhost] => {
    "changed": false,
    "msg": "All assertions passed"
}

TASK [synchronize : Cleanup] ***************************************************
changed: [testhost] => (item=foo.rsync_path) => {"ansible_loop_var": "item", "changed": true, "item": "foo.rsync_path", "path": "/root/ansible_collections/ansible/posix/tests/output/.tmp/output_dir/foo.rsync_path", "state": "absent"}

https://dev.azure.com/ansible/ansible.posix/_build/results?buildId=19837&view=logs&j=649027d1-4c8e-54ec-15ed-99c8fd6e3c09&t=e29e47f7-55c5-531b-4273-3a98ea9afdae&l=404

cmd.append(shlex_quote('--rsync-path=%s' % rsync_path))

if rsync_opts:
if '' in rsync_opts:
Expand All @@ -577,7 +577,7 @@ def main():
cmd.append('--link-dest=%s' % link_path)

changed_marker = '<<CHANGED>>'
cmd.append('--out-format=' + changed_marker + '%i %n%L')
cmd.append(shlex_quote('--out-format=' + changed_marker + '%i %n%L'))

# expand the paths
if '@' not in source:
Expand All @@ -601,10 +601,10 @@ def _write_password_to_pipe(proc):
raise

(rc, out, err) = module.run_command(
cmd, pass_fds=_sshpass_pipe,
cmdstr, pass_fds=_sshpass_pipe,
before_communicate_callback=_write_password_to_pipe)
else:
(rc, out, err) = module.run_command(cmd)
(rc, out, err) = module.run_command(cmdstr)

if rc:
return module.fail_json(msg=err, rc=rc, cmd=cmdstr)
Expand Down
1 change: 0 additions & 1 deletion tests/integration/targets/synchronize/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
shippable/posix/group1
disabled # fixme package