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.
checksum no no
  • yes
  • no
Skip based on checksum, rather than mod-time & size; Note that that "archive" option is still enabled by default - the "checksum" option will not disable it. (added in Ansible 1.6)
compress no yes
  • yes
  • no
Compress file data during the transfer. In most cases, leave this enabled unless it causes problems. (added in Ansible 1.7)
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. This option requires recursive=yes.
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_opts no
        Specify additional rsync options by passing in an array. (added in Ansible 1.6)
        rsync_path no
          Specify the rsync command to run on the remote machine. See --rsync-path on the rsync man page.
          rsync_timeout no
            Specify a --timeout for the rsync command in seconds.
            set_remote_user no True
              put user@ for the remote paths. If you have a custom ssh config to define the remote user for a host that does not match the inventory user, you should set this parameter to "no".
              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 with --archive options enabled except for --times, with --checksum option enabled
                synchronize: src=some/relative/path dest=/some/absolute/path checksum=yes times=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
                
                # Synchronize passing in extra rsync options
                synchronize: src=/tmp/helloworld dest=/var/www/helloword rsync_opts=--no-motd,--exclude=.git

                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.