Skip to content

Commit

Permalink
Merge pull request #278 from asnaedae/hotfix/escape_whitespace_in_paths
Browse files Browse the repository at this point in the history
Whitespace in fully  path to playbook causes rsync to fail

Any whitespace in path to playbook directory causes rsync to incorrectly chdir fail to correctly run.
SUMMARY
Any whitespace in path to playbook directory causes rsync to incorrectly chdir fail to correctly run.
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
ansible.posix.synchronize
ADDITIONAL INFORMATION


Example :
cd "/home/a/ansible plays"

task:
  - synchronize:
      src: a
      dest: b

Results in the following error being thrown
fatal: [remote-host]: FAILED! => {"changed": false, "cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --rsh='/usr/bin/ssh -S none -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' --rsync-path='sudo -u root rsync' --out-format='<<CHANGED>>%i %n%L' /home/a/ansible plays/deployments// remote-user@remote-host:/b/", "msg": "rsync: [sender] link_stat \"/home/a/ansible\" failed: No such file or directory (2)\nrsync: [sender] change_dir \"/home/a/ansible plays/plays/a/\" failed: No such file or directory (2)\nrsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1330) [sender=3.2.3]\n", "rc": 23}

Reviewed-by: Hideki Saito <[email protected]>
Reviewed-by: Abhijeet Kasurde <None>
Reviewed-by: None <None>
  • Loading branch information
ansible-zuul[bot] authored Nov 3, 2021
2 parents 3514f9d + d1be551 commit e366b90
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/shell_escape_full_path_for_rsync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- Fix for whitespace in source full path causing error ```code 23) at main.c(1330) [sender=3.2.3]``` (https://github.com/ansible-collections/ansible.posix/pull/278)
4 changes: 2 additions & 2 deletions plugins/modules/synchronize.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,8 @@ def main():
if '@' not in dest:
dest = os.path.expanduser(dest)

cmd.append(source)
cmd.append(dest)
cmd.append(shlex_quote(source))
cmd.append(shlex_quote(dest))
cmdstr = ' '.join(cmd)

# If we are using password authentication, write the password into the pipe
Expand Down
43 changes: 43 additions & 0 deletions tests/integration/targets/synchronize/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,46 @@
- directory_a/foo.txt
- directory_a
- directory_b

- name: setup - test for source with working dir with spaces in path
file:
state: directory
path: '{{output_dir}}/{{item}}'
delegate_to: '{{ inventory_hostname }}'
with_items:
- 'directory a'
- 'directory b'
- name: setup - create test new files
copy:
dest: '{{output_dir}}/directory a/{{item}}'
mode: '0644'
content: 'hello world'
with_items:
- foo.txt
delegate_to: '{{ inventory_hostname }}'
- name: copy source with spaces in dir path
synchronize:
src: '{{output_dir}}/directory a/foo.txt'
dest: '{{output_dir}}/directory b/'
delegate_to: '{{ inventory_hostname }}'
register: sync_result
ignore_errors: true
- name: get stat information for directory_b
stat:
path: '{{ output_dir }}/directory b/foo.txt'
register: stat_result_b
- assert:
that:
- '''changed'' in sync_result'
- sync_result.changed == true
- stat_result_b.stat.exists == True
- stat_result_b.stat.checksum == '2aae6c35c94fcfb415dbe95f408b9ce91ee846ed'
- name: Cleanup
file:
state: absent
path: '{{output_dir}}/{{item}}'
with_items:
- 'directory b/foo.txt'
- 'directory a/foo.txt'
- 'directory a'
- 'directory b'

0 comments on commit e366b90

Please sign in to comment.