2

需要解压缩 .zip 文件,然后列出解压缩的文件。这是选择一些文件模式并在其余代码中使用它们

我的剧本 yaml 片段是

- name: uarchive the opar zip
  unarchive:
   src: "{{opar_download_path}}/opar.zip"
   dest: "{{opar_download_path}}"
   remote_src: yes
   list_files: yes 

我无法找到有关如何使用“list_files”结果的详细信息,即如何将文件列表存储到变量中。我指的是下面的文档
https://docs.ansible.com/ansible/latest/modules/unarchive_module.html

4

1 回答 1

2

包括称为的list_files: yes附加响应属性files。为了更好的理解,尝试打印输出unarchived_list.files,如下图:

- name: unarchive the opar zip
  unarchive:
   src: "{{opar_download_path}}/opar.zip"
   dest: "{{opar_download_path}}"
   remote_src: yes
   list_files: yes
  register: unarchived_list

- name: print unarchived folder list of files
  debug: msg="{{unarchived_list.files}}"

可以在此处找到有关注册变量的更多信息:https ://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#registering-variables

于 2019-04-17T04:11:41.400 回答