Ansible Copy and unzip Module

I’m working on a copy module with two tasks.
First task is copying zip file from remote location to a tmp directory in managed node.
Second task is to copy the zip file to different directory for unzipping.
The problem is the zip file name changes constantly. How to make sure the second task picks the latest zip file.I don’t want to hardcode the file name it should be dynamic.

Hello @tharun232 ,

The unarchive module does have the option to list the files - list_files . The output can be registered, and usually the first value in the array is the directory name.

- name: Extract files
    src: /tmp/my_archive.tar.gz
    dest: /mydir
    remote_src: yes
    list_files: yes
  register: archive_contents

archive_contents.files[0] will have your top level directory.
Unarchive module doesn’t know what’s inside the archive – it just places all archive content into dest folder.

KodeKloud Support