我想用Ansible将文件从远程目录复制到本地目录,但是fetch模块允许我只复制一个文件.我有许多服务器,我需要文件(每个服务器的目录相同),我现在不知道如何使用Ansible.
有任何想法吗?
解决方法
你可能需要注册远程内容而不是循环它,这样的东西应该工作:
- shell: (cd /remote; find . -maxdepth 1 -type f) | cut -d'/' -f2 register: files_to_copy - fetch: src=/remote/{{ item }} dest=/local/ with_items: files_to_copy.stdout_lines
其中/ remote应使用远程服务器上的目录路径和/ local /上的目录路径进行更改