0

As I understand every ansible task is executed in context of some host. Let's call it "remote host".

For some ansible modules (f.e. fetch and copy) two hosts are involved: the "remote host" and the host where the ansible script is running (let's call it "local host").

Let's say we want to copy a file between two different remote hosts. How to copy files between two nodes using ansible suggests the following solution:

- hosts: ServerB
  tasks:
    - name: Transfer file from ServerA to ServerB
      synchronize:
        src: /path/on/server_a
        dest: /path/on/server_b
      delegate_to: ServerA

Looks like the effect of delegate_to in this case is that the task still runs in context of ServerB (remote host), but instead of local host the host specified by delegate_to is used (ServerA in this case).

But the behavior is quite different in the following case:

- hosts: ServerB
  tasks:
  - name: Copy file from local host to Server A
    copy:
      src: /local/path
      dest: /path/on/server_a
    delegate_to: ServerA

Even though values of hosts and delegate_to are the same in previous case, the copy operation happens between the local host and the host specified by delegate_to. So in this case delegate_to modifies not the local host, but remote host.

Why the behavior of delegate_to is different in these cases? Is it module-specific? But this parameter is not mentioned in ansible documentation of synchronize and copy modules, so I expected it's behavior should be the same for all modules.

lesnik
  • 2,507
  • 2
  • 25
  • 24
  • 3
    `synchronize` is a little special in this context. [Read the doc page of the module](https://docs.ansible.com/ansible/latest/modules/synchronize_module.html) to understand how it handles the option. In the most general case, `delegate_to` simply means "Use facts from the current play host (unless you also used `deletegate_facts`....) and play that module on this other host instead of the current play host". – Zeitounator Nov 28 '19 at 14:10
  • 3
    PS: you probably want to read this as well: https://docs.ansible.com/ansible/latest/user_guide/playbooks_delegation.html – Zeitounator Nov 28 '19 at 14:17

0 Answers0