Rsync –chown/–usermap Ignored – Troubleshooting Guide

debianrsync

I'm running ansible with the synchronize module, which underneath runs rsync.
My problem is not ansible-related, as I took the rsync command from the debug output and ran it manually – still the same issue.

The command I ran is:

/usr/bin/rsync --delay-updates -F --rsync-path="sudo rsync" --compress --delete-after --archive "/local/path" "ansible@1.2.3.4:/remote/path" --chown=myuser:myuser

Whatever I try – I end up with the directory belonging to root:root.

I therefore now rsync successfully runs as root, so it should have all neccessary permissions. I also tried using --usermap=*:myuser --groupmap=*:myuser – nothing.

I added --chmod=750 – not being applied.

In the debug output (-vvvv), I can see my parameters again, but that's it.

No warning, no error, but also no later mention of anything containing "user", "group", "chown" etc…
rsync is 3.1.1 on Debian 8.

Any help would be appreciated…

Best Answer

The chown system call (and, by extension, the chown and rsync --chown commands) may only be used by root. You're connecting to the remote system as the ansible user, so the remote system will not permit the operation. The rsync command recognizes that it's not running as root on the remote system, so it silently ignores the --chown option and others like it (e.g., --mapuser).

The rsync manual is not really explicit about this behavior, but if you specify the --super option as well, it will cause rsync on the remote system to assume it is running as root, even if it is not. This will allow it to attempt the chown operation, and to produce an error if or when it fails.

EDIT:

If you do manage to execute rsync on the remote system as root (e.g., using --rsync-path="sudo rsync"), you will still need to add a couple options for --chown to be usable. The manual states:

--chown=USER:GROUP
    This option forces all files to be owned by USER with group GROUP.
    This is a simpler interface than using --usermap and --groupmap
    directly, but it is implemented using those options internally, so
    you cannot mix them.

And here's what the manual says for --usermap and --groupmap:

--usermap=STRING, --groupmap=STRING
    ...
    For the --usermap option to have any effect, the -o (--owner)
    option must be used (or implied), and the receiver will need to
    be running as a super-user (see also the --fake-super option).
    For the --groupmap option to have any effect, the -g (--groups)
    option must be used (or implied), and the receiver will need to
    have permissions to set that group. 

In addition to using --rsync-path to run it under sudo, try adding the -o and -g options as well.