0%

Ansible part9: fetch file from remote

file module has a fetch module, which is the same as copy but in reverse.

1
2
3
4
5
6
tasks:
- name: fetech
fetch:
src: /tmp/ansible-file-test.txt
dest: /tmp/
flat:

go to my local machine to see /tmp directory

1
2
3
4
anna@ansible-controller:~/Desktop/ansible-code/inventory/modules/files-modules/inventory$ ll /tmp/ansible-node1/tmp/ansible-file-test.txt 
-rw-rw-r-- 1 anna anna 10 Jun 16 18:18 /tmp/ansible-node1/tmp/ansible-file-test.txt
anna@ansible-controller:~/Desktop/ansible-code/inventory/modules/files-modules/inventory$ ll /tmp/cube4200/tmp/ansible-file-test.txt
-rw-rw-r-- 1 anna anna 0 Jun 16 18:18 /tmp/cube4200/tmp/ansible-file-test.txt

there are two hosts directories which are relate to my two hosts.

for the flat, it means ansible will not distinct the files from different hosts, the latest file will overwrite the old one.
for example

1
2
3
4
5
6
tasks:
- name: fetech
fetch:
src: /tmp/ansible-file-test.txt
dest: /tmp/
flat: yes

notice: the default of flat is no, I am turning on it here, it will let the new file overwrite old file

1
2
3
4
5
anna@ansible-controller:~/Desktop/ansible-code/inventory/modules/files-modules/inventory$ ll /tmp
total 76
drwxrwxrwt 18 root root 4096 Jun 16 18:28 ./
drwxr-xr-x 24 root root 4096 Jun 9 20:21 ../
-rw-rw-r-- 1 anna anna 0 Jun 16 18:28 ansible-file-test.txt

from above, I can see there is only one ansible-file-test.txt file which is from cube4200, and there is no file from ansible-node1.