通过Windows上的通配符通过Ansible进行远程复制

时间:2019-08-08 07:00:51

标签: windows ansible

实际上,我试图通过ansible在Windows上“安装”(只需解压缩并移至我的首选文件夹)Perl。

该软件包将作为tar.gz复制到Windows系统,并将被提取两次,因为Windows解释tar.gz文件有点不同(首先将tar.gz解压缩为tar文件,然后解压缩tar文件)。 / p>

源代码将提取到C:\ Perl \ perl-5.30.0 \,我想将文件从那里移动到C:\ Perl。

由于文件是远程文件,因此我使用带有“ remote_src:是”选项的“ win_copy”模块。

文件正在使用以下方式复制:

  - name: Get Perl files for copying on Windows
    win_find:
      paths: '{{ perldir }}\perl-{{ perlversion }}'
    register: perl_move_files

  - name: Copy Perl files to main dir on Windows
    win_copy:
      src: '{{ item.path }}'
      dest: '{{ perldir }}\'
      remote_src: yes
    with_items:
      - '{{ perl_move_files.files }}'

但是ansible只复制文件,而不复制子目录下的所有文件。如何管理所有文件和子目录?

也许有些专家会读这篇文章?

感谢和问候, 大卫

2 个答案:

答案 0 :(得分:0)

fileglob用于在本地服务器中查找匹配项。对于远程服务器,您需要首先找到文件,然后复制。

---
 - name: Find files 
   win_find:
    paths: '{{ perldir }}\perl-{{ perlversion }}'
   register: perl_files
 - name: Copy
   win_copy:
      src: '{{ item.path }}'
      dest: '{{ perldir }}\'
      remote_src: yes
   with_items: "{{perl_files.files}}"

注意:此代码未经测试。

答案 1 :(得分:0)

我发现了另一个在这种情况下更有效的模块:win_robocopy(https://docs.ansible.com/ansible/latest/modules/win_robocopy_module.html

  - name: Copy Perl files to main dir over Robocopy on Windows
    win_robocopy:
      src: '{{ perldir }}\perl-{{ perlversion }}'
      dest: '{{ perldir }}'
      recurse: yes

非常感谢您的帮助!