Trouble syncing bunch of files using synchronize / sudo rsync

First of all i want to tell you how amazed i am with Ansible! The more i learn it the more amazed i am, it is a great peace of software.

But now, as always, i have a problem :slight_smile:

I’ve been having problems with rsync and ansible for a few days now, so i guess i am missing something obvious :slight_smile:

I want to rsync files from the host machine (ansible “master”) to some other machine but also overwrite some of the files on target machine that require sudo to access. Lets call my user test, this user exists on both “master” and target machine and is part of sudo group on both machines.

My play includes:

remote_user: nettv
sudo: True

.
.
.

  • name: RSYNC all the needed files for streamer
    #synchronize: src=/home/test/streamer-image/opt/ dest=/opt/ rsync_timeout=5 rsync_path=“sudo rsync”
    #command: sudo rsync -avP -e “ssh -o StrictHostChecking=no” --partial test@ansible-master.acme.com /streamer-image/opt/ /opt/
    local_action: shell rsync -avP “ssh -p {{ansible_ssh_port}}” --partial --rsync-path=“sudo rsync” /home/test/streamer-image/opt/ test@{{inventory_hostname}}:/opt/
    when: roles_var == “str”

When i try to use synchronize without sudo rsync i get permission denied which i think is normal.
When i try to use synchronize with sudo rsync i get that tty is not present. I have read about !requiretty but i would like to avoid this approach.
When i try to use command with sudo it just hangs (i guess it is waiting for sudo password but without a prompt)
When i try to use local_action with sudo i get that tty is not present.

In ansible.cfg I have this:

sudo_user = root #But i have tried with test also, but if i change to test my tasks won’t run because of premissions (this puzzles me)

executable = /bin/sh #But i have tired with /bin/bash also.

Files that are needed for example grub i will copy separately and describe handlers and such, but the rest of the files i need to copy “in bulk” and overwrite some of the files in /opt/, /etc/ and such.

So, what am i doing wrong? Am i missing something obvious? Is there some workaround?

If you need any verbose output for any of the cases i will be happy to provide them :slight_smile:

Any idea is highly appreciated! Thank you in advance!

Formatting is a bit wonky in the email. Could you put the playbook/tasks on gist or paste bin?

You might want to consider the recursive options to copy instead, they will be less efficient, but won’t require the tty.

@James Tanner of course!

This is site.yml which calls role streamer which in turn includes rsync.yml. I have made comments in pastebin which should put you right on the track.

http://pastebin.com/7NAWgwnp

@Michael DeHaan i have considered that (but didn’t try it tbh) because i read that copy module doesn’t handle large number of arguments (files) very well. Those static files that need to be copied number hundreds if not a thousand.

Thank you both for taking the interest in my problem :slight_smile:

"I want to rsync files from the host machine (ansible “master”) to some other machine but also overwrite some of the files on target machine that require sudo to access.”

This implies two things:

  1. you should not use local_action, because synchronize’s action plugin automatically does this “delegation” action and will not use remote paths if local_action is used.
  2. you will need to set the rsync_path option to enable sudo on the remote host

rsync_path=“sudo rsync”

Setting the rsync_path that way will imply two more things:

A) the user can sudo without a password
B) sudo does not require a tty

You are effectively doing all of this with your “local_action: shell” example, but you aren’t going to be able to get around the tty issue because that’s enforced by default in sudo. You’ll have to turn it off.

You have confirmed my suspicion about rsync then. I think i will be looking at the way to modify sudoers file to not require tty, rsync the content and then edit sudoers again to require tty (if this doesn’t require reboot) just for the sake of deployment of new servers. I do not require constant checking of rsynced files (if this is going to get cron-ed) so i guess i should be allright :slight_smile:

Thank you very much! You’ve been of great help!