Create some files (via templating) on the server
- name: Create backup configuration files
template:
src: "{{ item.type }}.yml.j2"
dest: "/tmp/{{ item.project }}_{{ item.env }}_{{ item.type }}.yml"
with_items:
- "{{ backup }}"
METHOD 1: using scp and delegate_to
- name: Copy configuration to Backup server
become: true
shell: "scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null admin@{{ inventory_hostname }}:/tmp/{{ item.project }}_{{ item.env }}_{{ item.type }}.yml /{{ backup.install_path }}/config/backups/{{ item.project }}_{{ item.env }}_{{ item.type }}.yml"
with_items:
- "{{ backup }}"
delegate_to: other.example.com
METHOD 2: using synchronize and delegate_to
- name: Copy configuration to Backup server
synchronize:
src: "/tmp/{{ item.project }}_{{ item.env }}_{{ item.type }}.yml"
dest: "/{{ backup.install_path }}/config/backups/{{ item.project }}_{{ item.env }}_{{ item.type }}.yml"
mode: pull
delegate_to: other.example.com
with_items:
- "{{ backup }}"
mode: pull
is important since the command (rsync) is run on the other server and it wants to pull the file.