1- name: install rsync
2  package:
3    name: rsync
4  when: ansible_distribution != "MacOSX"
5- name: cleanup old files
6  shell: rm -rf {{output_dir}}/*
7- name: create test new files
8  copy: dest={{output_dir}}/{{item}} mode=0644 content="hello world"
9  with_items:
10  - foo.txt
11  - bar.txt
12- name: synchronize file to new filename
13  synchronize: src={{output_dir}}/foo.txt dest={{output_dir}}/foo.result
14  register: sync_result
15- assert:
16    that:
17    - '''changed'' in sync_result'
18    - sync_result.changed == true
19    - '''cmd'' in sync_result'
20    - '''rsync'' in sync_result.cmd'
21    - '''msg'' in sync_result'
22    - sync_result.msg.startswith('>f+')
23    - 'sync_result.msg.endswith(''+ foo.txt
24
25      '')'
26- name: test that the file was really copied over
27  stat:
28    path: '{{ output_dir }}/foo.result'
29  register: stat_result
30- assert:
31    that:
32    - stat_result.stat.exists == True
33    - stat_result.stat.checksum == '2aae6c35c94fcfb415dbe95f408b9ce91ee846ed'
34- name: test that the file is not copied a second time
35  synchronize: src={{output_dir}}/foo.txt dest={{output_dir}}/foo.result
36  register: sync_result
37- assert:
38    that:
39    - sync_result.changed == False
40- name: Cleanup
41  file:
42    state: absent
43    path: '{{output_dir}}/{{item}}'
44  with_items:
45  - foo.result
46  - bar.result
47- name: Synchronize using the mode=push param
48  synchronize:
49    src: '{{output_dir}}/foo.txt'
50    dest: '{{output_dir}}/foo.result'
51    mode: push
52  register: sync_result
53- assert:
54    that:
55    - '''changed'' in sync_result'
56    - sync_result.changed == true
57    - '''cmd'' in sync_result'
58    - '''rsync'' in sync_result.cmd'
59    - '''msg'' in sync_result'
60    - sync_result.msg.startswith('>f+')
61    - 'sync_result.msg.endswith(''+ foo.txt
62
63      '')'
64- name: test that the file was really copied over
65  stat:
66    path: '{{ output_dir }}/foo.result'
67  register: stat_result
68- assert:
69    that:
70    - stat_result.stat.exists == True
71    - stat_result.stat.checksum == '2aae6c35c94fcfb415dbe95f408b9ce91ee846ed'
72- name: test that the file is not copied a second time
73  synchronize:
74    src: '{{output_dir}}/foo.txt'
75    dest: '{{output_dir}}/foo.result'
76    mode: push
77  register: sync_result
78- assert:
79    that:
80    - sync_result.changed == False
81- name: Cleanup
82  file:
83    state: absent
84    path: '{{output_dir}}/{{item}}'
85  with_items:
86  - foo.result
87  - bar.result
88- name: Synchronize using the mode=pull param
89  synchronize:
90    src: '{{output_dir}}/foo.txt'
91    dest: '{{output_dir}}/foo.result'
92    mode: pull
93  register: sync_result
94- assert:
95    that:
96    - '''changed'' in sync_result'
97    - sync_result.changed == true
98    - '''cmd'' in sync_result'
99    - '''rsync'' in sync_result.cmd'
100    - '''msg'' in sync_result'
101    - sync_result.msg.startswith('>f+')
102    - 'sync_result.msg.endswith(''+ foo.txt
103
104      '')'
105- name: test that the file was really copied over
106  stat:
107    path: '{{ output_dir }}/foo.result'
108  register: stat_result
109- assert:
110    that:
111    - stat_result.stat.exists == True
112    - stat_result.stat.checksum == '2aae6c35c94fcfb415dbe95f408b9ce91ee846ed'
113- name: test that the file is not copied a second time
114  synchronize:
115    src: '{{output_dir}}/foo.txt'
116    dest: '{{output_dir}}/foo.result'
117    mode: pull
118  register: sync_result
119- assert:
120    that:
121    - sync_result.changed == False
122- name: Cleanup
123  file:
124    state: absent
125    path: '{{output_dir}}/{{item}}'
126  with_items:
127  - foo.result
128  - bar.result
129- name: synchronize files using with_items (issue#5965)
130  synchronize: src={{output_dir}}/{{item}} dest={{output_dir}}/{{item}}.result
131  with_items:
132  - foo.txt
133  - bar.txt
134  register: sync_result
135- assert:
136    that:
137    - sync_result.changed
138    - sync_result.msg == 'All items completed'
139    - '''results'' in sync_result'
140    - sync_result.results|length == 2
141    - 'sync_result.results[0].msg.endswith(''+ foo.txt
142
143      '')'
144    - 'sync_result.results[1].msg.endswith(''+ bar.txt
145
146      '')'
147- name: Cleanup
148  file:
149    state: absent
150    path: '{{output_dir}}/{{item}}.result'
151  with_items:
152  - foo.txt
153  - bar.txt
154- name: synchronize files using rsync_path (issue#7182)
155  synchronize: src={{output_dir}}/foo.txt dest={{output_dir}}/foo.rsync_path rsync_path="sudo rsync"
156  register: sync_result
157- assert:
158    that:
159    - '''changed'' in sync_result'
160    - sync_result.changed == true
161    - '''cmd'' in sync_result'
162    - '''rsync'' in sync_result.cmd'
163    - '''rsync_path'' in sync_result.cmd'
164    - '''msg'' in sync_result'
165    - sync_result.msg.startswith('>f+')
166    - 'sync_result.msg.endswith(''+ foo.txt
167
168      '')'
169- name: Cleanup
170  file:
171    state: absent
172    path: '{{output_dir}}/{{item}}'
173  with_items:
174  - foo.rsync_path
175- name: add subdirectories for link-dest test
176  file:
177    path: '{{output_dir}}/{{item}}/'
178    state: directory
179    mode: '0755'
180  with_items:
181  - directory_a
182  - directory_b
183- name: copy foo.txt into the first directory
184  synchronize:
185    src: '{{output_dir}}/foo.txt'
186    dest: '{{output_dir}}/{{item}}/foo.txt'
187  with_items:
188  - directory_a
189- name: synchronize files using link_dest
190  synchronize:
191    src: '{{output_dir}}/directory_a/foo.txt'
192    dest: '{{output_dir}}/directory_b/foo.txt'
193    link_dest:
194    - '{{output_dir}}/directory_a'
195  register: sync_result
196- name: get stat information for directory_a
197  stat:
198    path: '{{ output_dir }}/directory_a/foo.txt'
199  register: stat_result_a
200- name: get stat information for directory_b
201  stat:
202    path: '{{ output_dir }}/directory_b/foo.txt'
203  register: stat_result_b
204- assert:
205    that:
206    - '''changed'' in sync_result'
207    - sync_result.changed == true
208    - stat_result_a.stat.inode == stat_result_b.stat.inode
209- name: synchronize files using link_dest that would be recursive
210  synchronize:
211    src: '{{output_dir}}/foo.txt'
212    dest: '{{output_dir}}/foo.result'
213    link_dest:
214    - '{{output_dir}}'
215  register: sync_result
216  ignore_errors: true
217- assert:
218    that:
219    - sync_result is not changed
220    - sync_result is failed
221- name: Cleanup
222  file:
223    state: absent
224    path: '{{output_dir}}/{{item}}'
225  with_items:
226  - directory_b/foo.txt
227  - directory_a/foo.txt
228  - directory_a
229  - directory_b
230