-
Notifications
You must be signed in to change notification settings - Fork 1
/
rsync-remote.yml
62 lines (52 loc) · 1.84 KB
/
rsync-remote.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
---
- name: create an admin user (i.e. a non-root sudoer)
hosts: all:!development
remote_user: root
roles:
- create_admin_user
- name: rsync between remote machines
hosts: ansible-pocs-1
remote_user: "{{ admin_user.name }}"
become: no
become_method: sudo
become_user: root
tasks:
- name: create folder on src to sync
file:
state: directory
path: ~/syncthis
delegate_to: ansible-pocs-2
- name: create file on src to sync
file:
state: touch
path: ~/syncthis/{{ ansible_date_time.epoch }}
delegate_to: ansible-pocs-2
## This playbook is run against host ansible-pocs-1, but this task is
## delegated to ansible-pocs-2. In practice this means that the task
## first logs into ansible-pocs-2 and then runs rsync from there back
## to ansible-pocs-1.
- name: sync remote folder to remote folder
synchronize:
src: /home/admin/syncthis
dest: /home/admin
# archive: yes ## default is yes
# recursive: yes ## default is value of 'archive'
## hence, it is not necessary to explicitly set recursive: yes
# mode: push ## default is push
delegate_to: ansible-pocs-2
- name: check file was synced
stat:
path: ~/syncthis/{{ ansible_date_time.epoch }}
register: stat_result
- fail:
msg: 'file was not synced'
when: stat_result.stat.exists == False
## This task does the same as the earlier sync task, except we are
## supplying the delegate host as a variable - in this case, the
## second machine listed in the staging group (index 1).
## Left here as a reminder of this technique.
- name: sync remote folders using var as delegate
synchronize:
src: /home/admin/syncthis
dest: /home/admin
delegate_to: "{{ groups['staging'][1] }}"