--- - name: Copy the contents of the "/var/log" folder to the Ansible controller hosts: all_servers become: yes tasks: - name: Generate the list of files to be copied ansible.builtin.shell: "cd /var/log; find . -maxdepth 1 -type f | cut -d'/' -f2" register: files_to_copy - name: Copy the log files ansible.builtin.fetch: src: /var/log/{{ item }} dest: /home/vlad/Desktop/ansible/dnaclab_linux/logs/ with_items: "{{ files_to_copy.stdout_lines }}"