How to use fetch module in ansible

Viewed 1324

I want to copy file from remote server to local machine using ansible playbook. But when I do that using fetch module folder with server IP gets created on local machine with complete directory structure. Is there a way to avoid that? Below is my task from playbook

- name: Copy files from remote to local
  fetch:
    src: /etc/pki/ca.pem
    dest: /etc/workloadmgr
1 Answers

Use flat option of fetch:

Allows you to override the default behavior of appending hostname/path/to/file to the destination. If dest ends with '/', it will use the basename of the source file, similar to the copy module. This can be useful if working with a single host, or if retrieving files that are uniquely named per host. If using multiple hosts with the same filename, the file will be overwritten for each host.

Like this

- name: Copy files from remote to local
  fetch:
    src: /etc/pki/ca.pem
    dest: /etc/workloadmgr
    flat: yes
Related