Ansible:从HTTP服务器获取动态文件列表

时间:2018-11-24 21:34:16

标签: ansible

我在Nexus服务器上有一堆文件,并且可以通过Web浏览器使用REST服务浏览原始存储库。

该站点上的zip文件不是静态的,并且可能具有随机名称。

我已经尝试过unarchiveget_url模块,但只有在我知道远程文件名的情况下它们才起作用。

我现在唯一的选择是使用command模块并使用curl或wget下载文件。

wget -r -np -l 1 -A zip \ 
http://localhost:8081/service/rest/repository/browse/repo/installs/latest/

是否有使用Ansible模块实现此目标的更好方法?

谢谢

1 个答案:

答案 0 :(得分:1)

  

是否有使用Ansible模块实现此目标的更好方法?

- uri:
    url: http://localhost:8081/service/rest/repository/browse/repo/installs/latest/
    return_content: yes
  register: the_files
- debug: var=the_zips
  vars:
    the_zips: >-
     {{ the_files.content | regex_findall("\w+\.zip") }}

将是我的猜测,但这实际上取决于我们在讨论这些文件名时到底有多“随机”。