Extracting multi part zip files with Ansible (Example case: WebSphere installation)

2.7k Views Asked by At

For HCL Connections, we still need WebSphere and I want to automate this complex and slow process with Ansible. WebSphere needs to be manually downloaded with differenet ZIP files for each component, for example:

├── CIK1VML.zip
├── CIK1WML.zip
└── CIK1XML.zip

The char after CIK1 identifies the part. On the command line, I can unzip them by replacing those part identifier with a question mark:

 unzip '/cnx-smb/was/supplements/CIK1?ML.zip' -d /tmp/was-suppl-manual

I'd like to use the unarchive module cause it supports features like remote_src which would be usefull for me, so I tried a simple POC playbook:

- hosts: 127.0.0.1
  connection: local
  tasks:
    - name: Unpack test
      become: yes
      unarchive:
        src: "/cnx-smb/was/supplements/CIK1?ML.zip"
        remote_src: no
        dest: "/tmp/was-extracted"

But this doesn't work:

TASK [Unpack test] **********************************************************************************************************************************************************************************************************************************************************
Wednesday 10 February 2021  16:17:25 +0000 (0:00:00.637)       0:00:00.651 ****
fatal: [127.0.0.1]: FAILED! => changed=false
  msg: |-
    Could not find or access '/cnx-smb/was/supplements/'CIK1?ML.zip'' on the Ansible Controller.
    If you are using a module and expect the file to exist on the remote, see the remote_src option

I also tried different src paths like /cnx-smb/was/supplements/'CIK1?ML.zip', cause the unzip CLI call works only when at least the filename is masked in quotes, or alternatively the entire path. Ansible accepts only when the file name is quoted, '/cnx-smb/was/supplements/CIK1?ML.zip' seems to be interpreted as relative path (which obviously fails).

1

There are 1 best solutions below

0
On

It seems that those multipart zip-archives aren't really "multi part" archives, as I know from compression formats like 7zip where we have File.partX.7z which are only used together. 7zip validates them and throws an error if e.g. a part is missing.

The situation is different on those zip files. I took a look in them and noticed that I can extract every single zip file without the others. Every zip file contains a part of the installation archive. It seems that zip itself doesn't divide a large folder into parts. It's IBM who put some folders like disk2 in a seperate archive file for whatever reason.

This means I can do the same with ansible: Just extract every single file on its own, but in the same directory:

- hosts: 127.0.0.1
  connection: local
  vars:
    base_dir: /cnx-smb/was/supplements/

  tasks:
    - name: Unpack
      become: yes
      unarchive:
        src: "{{ base_dir }}/{{ item }}"
        remote_src: no
        dest: "/tmp/was-extracted"
      with_items: 
        - CIK1VML.zip
        - CIK1WML.zip
        - CIK1XML.zip

Both extracted folderse (Ansible + manually using zip command with ? placeholder) were of the same size and contains the same data:

vagrant@ansible:/cnx-repo$ du -hs /tmp/was-extracted/
3.0G    /tmp/was-extracted/
vagrant@ansible:/cnx-repo$ du -hs /tmp/was-suppl-manual
3.0G    /tmp/was-suppl-manual