---
- name: Fetch hosts file from remote servers
hosts: all
become: True
tasks:
- name: Fetch the output file
fetch:
src: /etc/hosts
dest: /home/ansible/
output :
The files fetched from the respective remote servers will be placed under a subdirectory named as the hostname of that server. The directory hierarchy will be copied as well.
See next example for alternative way of saving at the destination.