ansiblebusybox

Ansible - unarchive module not working with busy box tools


I am trying to unzip a file on an embedded system that has busy box.

- name: Unarchive media files
  unarchive:
    src: /home/root/archive.zip
    dest: /home/root/
    remote_src: yes

I am getting the following error:

fatal: [10.0.6.41]: FAILED! => {"changed": false, "msg": "Failed to find handler for \"/home/root/archive.zip\". Make sure the required command to extract the file is installed.\nCommand \"/bin/tar\" detected as tar type None. GNU tar required.\nCommand \"unzip -Z\" could not handle archive: /usr/bin/unzip: invalid option -- 'Z'\nBusyBox v1.31.1 () multi-call binary.\n\nUsage: unzip [-lnojpq] FILE[.zip] [FILE]... [-x FILE...] [-d DIR]\n\nUnable to find required 'zipinfo' binary in the path."}

Seems like it requires GNU tar? If I run unzip archive.zip directly on the command line on the remote source, it is working.


Solution

  • The last portion of your log says everything:

    Unable to find required 'zipinfo' binary in the path
    

    Ansible tries to run unzip -Z which is the same as zipinfo:

    Command \"unzip -Z\" could not handle archive: /usr/bin/unzip: invalid option -- 'Z'
    

    From unarchive module documentation:

    Requires zipinfo and gtar/unzip command on target host.

    It's not the Ansible way, but if you're on an embedded system and with busybox chances are that you will not be able to install zipinfo or any other package. So you can always run unzip directly using command or shell module:

    - name: Unarchive media files
      command:
        cmd: unzip archive.zip
        creates: archive
        chdir: /home/root/