ansible.builtin.synchronize (v2.4.3.0-1) — module

A wrapper around rsync to make common tasks in your playbooks quick and easy.

| "added in version" 1.4 of ansible.builtin"

Authors: Timothy Appnel (@tima)

preview | supported by core

Install Ansible via pip

Install with pip install ansible==2.4.3.0.post1

Description

C(synchronize) is a wrapper around rsync to make common tasks in your playbooks quick and easy. It is run and originates on the local host where Ansible is being run. Of course, you could just use the C(command) action to call rsync yourself, but you also have to add a fair number of boilerplate options and host facts. C(synchronize) is not intended to provide access to the full power of rsync, but does make the most common invocations easier to implement. You `still` may need to call rsync directly via C(command) or C(shell) depending on your use case.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Synchronization of src on the control machine to dest on the remote hosts
- synchronize:
    src: some/relative/path
    dest: /some/absolute/path
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Synchronization using rsync protocol (push)
- synchronize:
    src: some/relative/path/
    dest: rsync://somehost.com/path/
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Synchronization using rsync protocol (pull)
- synchronize:
    mode: pull
    src: rsync://somehost.com/path/
    dest: /some/absolute/path/
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Synchronization using rsync protocol on delegate host (push)
- synchronize:
    src: /some/absolute/path/
    dest: rsync://somehost.com/path/
  delegate_to: delegate.host
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Synchronization using rsync protocol on delegate host (pull)
- synchronize:
    mode: pull
    src: rsync://somehost.com/path/
    dest: /some/absolute/path/
  delegate_to: delegate.host
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Synchronization without any --archive options enabled
- synchronize:
    src: some/relative/path
    dest: /some/absolute/path
    archive: no
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Synchronization with --archive options enabled except for --recursive
- synchronize:
    src: some/relative/path
    dest: /some/absolute/path
    recursive: no
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Synchronization without --archive options enabled except use --links
- synchronize:
    src: some/relative/path
    dest: /some/absolute/path
    archive: no
    links: yes
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Synchronization of two paths both on the control machine
- synchronize:
    src: some/relative/path
    dest: /some/absolute/path
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Synchronization of src on delegate host to dest on the current inventory host.
- synchronize:
    src: /first/absolute/path
    dest: /second/absolute/path
  delegate_to: delegate.host
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Synchronize two directories on one remote host.
- synchronize:
    src: /first/absolute/path
    dest: /second/absolute/path
  delegate_to: "{{ inventory_hostname }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
    recursive: yes
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Synchronize using an alternate rsync command
# This specific command is granted su privileges on the destination
- synchronize:
    src: some/relative/path
    dest: /some/absolute/path
    rsync_path: "su -c rsync"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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/helloworld
    rsync_opts:
      - "--no-motd"
      - "--exclude=.git"

Inputs

    
src:
    description:
    - Path on the source host that will be synchronized to the destination; The path can
      be absolute or relative.
    required: true

dest:
    description:
    - Path on the destination host that will be synchronized from the source; The path
      can be absolute or relative.
    required: true

dirs:
    choices:
    - 'yes'
    - 'no'
    default: 'no'
    description:
    - Transfer directories without recursing
    required: false

mode:
    choices:
    - push
    - pull
    default: push
    description:
    - Specify the direction of the synchronization. In push mode the localhost or delegate
      is the source; In pull mode the remote host in context is the source.
    required: false

group:
    choices:
    - 'yes'
    - 'no'
    default: the value of the archive option
    description:
    - Preserve group
    required: false

links:
    choices:
    - 'yes'
    - 'no'
    default: the value of the archive option
    description:
    - Copy symlinks as symlinks.
    required: false

owner:
    choices:
    - 'yes'
    - 'no'
    default: the value of the archive option
    description:
    - Preserve owner (super user only)
    required: false

perms:
    choices:
    - 'yes'
    - 'no'
    default: the value of the archive option
    description:
    - Preserve permissions.
    required: false

times:
    choices:
    - 'yes'
    - 'no'
    default: the value of the archive option
    description:
    - Preserve modification times
    required: false

delete:
    choices:
    - 'yes'
    - 'no'
    default: 'no'
    description:
    - Delete files in C(dest) that don't exist (after transfer, not before) in the C(src)
      path. This option requires C(recursive=yes).
    required: false

archive:
    choices:
    - 'yes'
    - 'no'
    default: 'yes'
    description:
    - Mirrors the rsync archive flag, enables recursive, links, perms, times, owner, group
      flags and -D.
    required: false

partial:
    default: false
    description:
    - Tells rsync to keep the partial file which should make a subsequent transfer of
      the rest of the file much faster.
    required: false
    version_added: '2.0'
    version_added_collection: ansible.builtin

checksum:
    choices:
    - 'yes'
    - 'no'
    default: 'no'
    description:
    - 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.
    required: false
    version_added: '1.6'
    version_added_collection: ansible.builtin

compress:
    choices:
    - 'yes'
    - 'no'
    default: 'yes'
    description:
    - Compress file data during the transfer. In most cases, leave this enabled unless
      it causes problems.
    required: false
    version_added: '1.7'
    version_added_collection: ansible.builtin

dest_port:
    default: Value of ansible_ssh_port for this host, remote_port config setting, or the
      value from ssh client configuration if none of those are set
    description:
    - Port number for ssh on the destination host. Prior to ansible 2.0, the ansible_ssh_port
      inventory var took precedence over this value.
    version_added: '1.5'
    version_added_collection: ansible.builtin

recursive:
    choices:
    - 'yes'
    - 'no'
    default: the value of the archive option
    description:
    - Recurse into directories.
    required: false

copy_links:
    choices:
    - 'yes'
    - 'no'
    default: 'no'
    description:
    - Copy symlinks as the item that they point to (the referent) is copied, rather than
      the symlink.
    required: false

rsync_opts:
    default: null
    description:
    - Specify additional rsync options by passing in an array.
    required: false
    version_added: '1.6'
    version_added_collection: ansible.builtin

rsync_path:
    description:
    - Specify the rsync command to run on the remote host. See C(--rsync-path) on the
      rsync man page.
    required: false

verify_host:
    default: false
    description:
    - Verify destination host key.
    required: false
    version_added: '2.0'
    version_added_collection: ansible.builtin

use_ssh_args:
    choices:
    - 'yes'
    - 'no'
    default: 'no'
    description:
    - Use the ssh_args specified in ansible.cfg
    version_added: '2.0'
    version_added_collection: ansible.builtin

existing_only:
    choices:
    - 'yes'
    - 'no'
    default: 'no'
    description:
    - Skip creating new files on receiver.
    required: false
    version_added: '1.5'
    version_added_collection: ansible.builtin

rsync_timeout:
    default: 0
    description:
    - Specify a --timeout for the rsync command in seconds.
    required: false

set_remote_user:
    default: true
    description:
    - 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".