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, thechown
andrsync --chown
commands) may only be used byroot
. You're connecting to the remote system as theansible
user, so the remote system will not permit the operation. Thersync
command recognizes that it's not running asroot
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 causersync
on the remote system to assume it is running asroot
, even if it is not. This will allow it to attempt thechown
operation, and to produce an error if or when it fails.EDIT:
If you do manage to execute
rsync
on the remote system asroot
(e.g., using--rsync-path="sudo rsync"
), you will still need to add a couple options for--chown
to be usable. The manual states:And here's what the manual says for
--usermap
and--groupmap
:In addition to using
--rsync-path
to run it undersudo
, try adding the-o
and-g
options as well.