我想使用 ansible playbook 将文件从远程服务器复制到本地计算机。但是,当我使用 fetch module 执行此操作时,会在本地计算机上创建具有完整目录结构的服务器 IP 文件夹。有办法避免这种情况吗?以下是我的剧本中的任务
- name: Copy files from remote to local
fetch:
src: /etc/pki/ca.pem
dest: /etc/workloadmgr
最佳答案
使用fetch
的flat
选项:
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.
像这样
- name: Copy files from remote to local
fetch:
src: /etc/pki/ca.pem
dest: /etc/workloadmgr
flat: yes
关于ansible - 如何在ansible中使用fetch模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63415143/