synchronize - Uses rsync to make synchronizing file paths in your playbooks quick and easy.

Author:Timothy Appnel

Synopsis

New in version 1.4.

This is a wrapper around rsync. Of course you could just use the command action to call rsync yourself, but you also have to add a fair number of boilerplate options and host facts. You still may need to call rsync directly via command or shell depending on your use case. The synchronize action is meant to do common things with rsync easily. It does not provide access to the full power of rsync, but does make most invocations easier to follow.

Options

parameter required default choices comments
archive no yes
  • yes
  • no
Mirrors the rsync archive flag, enables recursive, links, perms, times, owner, group flags and -D.
copy_links no no
  • yes
  • no
Copy symlinks as the item that they point to (the referent) is copied, rather than the symlink.
delete no no
  • yes
  • no
Delete files that don't exist (after transfer, not before) in the src path.
dest yes
    Path on the destination machine that will be synchronized from the source; The path can be absolute or relative.
    dest_port no 22
      Port number for ssh on the destination host. The ansible_ssh_port inventory var takes precedence over this value. (added in Ansible 1.5)
      dirs no no
      • yes
      • no
      Transfer directories without recursing
      existing_only no no
      • yes
      • no
      Skip creating new files on receiver. (added in Ansible 1.5)
      group no the value of the archive option
      • yes
      • no
      Preserve group
      links no the value of the archive option
      • yes
      • no
      Copy symlinks as symlinks.
      mode no push
      • push
      • pull
      Specify the direction of the synchroniztion. In push mode the localhost or delegate is the source; In pull mode the remote host in context is the source.
      owner no the value of the archive option
      • yes
      • no
      Preserve owner (super user only)
      perms no the value of the archive option
      • yes
      • no
      Preserve permissions.
      recursive no the value of the archive option
      • yes
      • no
      Recurse into directories.
      rsync_path no
        Specify the rsync command to run on the remote machine. See --rsync-path on the rsync man page.
        rsync_timeout no 10
          Specify a --timeout for the rsync command in seconds.
          src yes
            Path on the source machine that will be synchronized to the destination; The path can be absolute or relative.
            times no the value of the archive option
            • yes
            • no
            Preserve modification times

            Examples


            # Synchronization of src on the control machine to dest on the remote hosts
            synchronize: src=some/relative/path dest=/some/absolute/path
            
            # Synchronization without any --archive options enabled
            synchronize: src=some/relative/path dest=/some/absolute/path archive=no
            
            # Synchronization with --archive options enabled except for --recursive
            synchronize: src=some/relative/path dest=/some/absolute/path recursive=no
            
            # Synchronization without --archive options enabled except use --links
            synchronize: src=some/relative/path dest=/some/absolute/path archive=no links=yes
            
            # Synchronization of two paths both on the control machine
            local_action: synchronize src=some/relative/path dest=/some/absolute/path
            
            # Synchronization of src on the inventory host to the dest on the localhost in
            pull mode
            synchronize: mode=pull src=some/relative/path dest=/some/absolute/path
            
            # Synchronization of src on delegate host to dest on the current inventory host
            synchronize: >
                src=some/relative/path dest=/some/absolute/path
                delegate_to: delegate.host
            
            # Synchronize and delete files in dest on the remote host that are not found in src of localhost.
            synchronize: src=some/relative/path dest=/some/absolute/path delete=yes
            
            # Synchronize using an alternate rsync command
            synchronize: src=some/relative/path dest=/some/absolute/path rsync_path="sudo rsync"
            
            # Example .rsync-filter file in the source directory
            - var       # exclude any path whose last part is 'var'
            - /var      # exclude any path starting with 'var' starting at the source directory
            + /var/conf # include /var/conf even though it was previously excluded
            

            Note

            Inspect the verbose output to validate the destination user/host/path are what was expected.

            Note

            The remote user for the dest path will always be the remote_user, not the sudo_user.

            Note

            Expect that dest=~/x will be ~<remote_user>/x even if using sudo.

            Note

            To exclude files and directories from being synchronized, you may add .rsync-filter files to the source directory.