2

My zip file contains a folder UAT-04022021_01 which has several files.

ls output on my local ansible server zip achieve file and its contents below:

-rwxrwxr-x 1 user1 user1 171910544 Feb  4 07:02 /web

/playbooks/automation/deployments/tmpfiles/04/UAT-04022021_01.zip
$ unzip -l "/web/playbooks/automation/deployments/tmpfiles/04/UAT-04022021_01.zip"
Archive:  /web/playbooks/automation/deployments/tmpfiles/04/UAT-04022021_01.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  02-04-2021 17:31   UAT-04022021_01/
144241065  02-04-2021 15:58   UAT-04022021_01/canv.ear
  8342584  02-04-2021 16:00   UAT-04022021_01/canpizza.ear
 10522141  02-04-2021 16:01   UAT-04022021_01/cantity.ear
  8778258  02-04-2021 15:59   UAT-04022021_01/canipc.ear
---------                     -------
171884048                     5 files
[user1@linuxlocalhost deployments]$

Below is my code to extract the zip to all remote destination hosts

---
- name: "Play 1"
  host: "{{ dest_host }}"
  user: "{{ USER }}"

   - name: Give better permissions to the zip file
     tags: validate
     file:
       path: "{{ playbook_dir }}/tmpfiles/{{ Latest_Build_Number }}/{{ depfile | basename }}"
       mode: 0775
     delegate_to: localhost
     run_once: true

   - name: "Untar artifacts in CURRENT Folder"
     tags: validate
     unarchive:
       src: "{{ playbook_dir }}/tmpfiles/{{ Latest_Build_Number }}/{{ depfile | basename }}"
       dest: "/web/bea_apps/applications/{{ domain_home }}/{{ item }}/CURRENT/"
     with_items: "{{ CLUSTER.split(',') }}"

Output:

#############################################\n\n')
The full traceback is:
  File "/tmp/ansible_MCNgND/ansible_module_unarchive.py", line 873, in main
    res_args['changed'] = module.set_fs_attributes_if_different(file_args, res_args['changed'], expand=False)
  File "/tmp/ansible_MCNgND/ansible_modlib.zip/ansible/module_utils/basic.py", line 1473, in set_fs_attributes_if_different
    file_args['path'], file_args['mode'], changed, diff, expand
  File "/tmp/ansible_MCNgND/ansible_modlib.zip/ansible/module_utils/basic.py", line 1204, in set_mode_if_different
    path_stat = os.lstat(b_path)

failed: [myserver2] (item=VL_BATCH) => {
    "changed": false,
    "dest": "/web/bea_apps/applications/mydom1/VL_BATCH/CURRENT/",
    "gid": 64332,
    "group": "wladmin",
    "handler": "ZipArchive",
    "invocation": {
        "module_args": {
            "attributes": null,
            "backup": null,
            "content": null,
            "creates": null,
            "delimiter": null,
            "dest": "/web/bea_apps/applications/mydom1/VL_BATCH/CURRENT/",
            "directory_mode": null,
            "exclude": [],
            "extra_opts": [],
            "follow": false,
            "force": null,
            "group": null,
            "keep_newer": false,
            "list_files": false,
            "mode": null,
            "original_basename": "UAT-04022021_01.zip",
            "owner": null,
            "regexp": null,
            "remote_src": false,
            "selevel": null,
            "serole": null,
            "setype": null,
            "seuser": null,
            "src": "/home/wladmin/.ansible/tmp/ansible-tmp-1612477399.28-110140157282432/source",
            "unsafe_writes": null,
            "validate_certs": true
        }
    },
    "item": "VL_BATCH",
    "mode": "0755",
    "msg": "Unexpected error when accessing exploded file: [Errno 2] No such file or directory: '/web/bea_apps/applications/mydom1/VL_BATCH/CURRENT/UAT-04022021_01/'",
    "owner": "wladmin",
    "size": 2,
    "src": "/home/wladmin/.ansible/tmp/ansible-tmp-1612477399.28-110140157282432/source",
    "state": "directory",
    "uid": 600000008
}

/web/bea_apps/applications/mydom1/VL_BATCH/CURRENT/ is empty and has permission for the user to write to.

I checked on the destination and it does contain this folder /web/bea_apps/applications/mydom1/VL_BATCH/CURRENT/ but not /web/bea_apps/applications/mydom1/VL_BATCH/CURRENT/UAT-04022021_01/

It was supposed to create this folder UAT-04022021_01 if it unzips under the CURRENT folder.

After researching a bit more I tried this suggested fix of environment but it does not help either.

   - name: "Untar artifacts in CURRENT Folder"
     tags: validate
     unarchive:
       src: "{{ playbook_dir }}/tmpfiles/{{ Latest_Build_Number }}/{{ depfile | basename }}"
       dest: "/web/bea_apps/applications/{{ domain_home }}/{{ item }}/CURRENT/"
     with_items: "{{ CLUSTER.split(',') }}"
     environment:
       LANG: C
       LC_ALL: C
       LC_MESSAGES: C

My source is Linux while destination is Solaris.

Can you please suggest what could be wrong?

Ashar
  • 2,942
  • 10
  • 58
  • 122
  • Does the remote host have the `zipinfo` and `unzip` commands installed? – larsks Feb 05 '21 at 00:13
  • Yes, it has both @larsks I'm on ansible version 2.4.2.0. Also updated the original post with another fix that I tried but failed. – Ashar Feb 05 '21 at 00:14
  • tried this solution but does not help -> https://github.com/ansible/ansible-modules-core/issues/3706 – Ashar Feb 05 '21 at 00:21
  • 1
    What do the contents of `UAT-04022021_01.zip` look like? Can you reproduce this problem with *any* zip file, or is the problem specific to that file? Does the problem reproduce if you point your playbook at your local host rather than the remote Solaris host? – larsks Feb 05 '21 at 00:30
  • Your question is precise and that's exactly the behavior. When the playbook runs locally the zip gets unzipped fine. The issue is only when we have remote host @larsks – Ashar Feb 05 '21 at 00:32
  • updated original post for How does `UAT-04022021_01.zip` look like. – Ashar Feb 05 '21 at 00:42
  • I can't reproduce this behavior; I even tried spinning up an [OpenIndiana](https://www.openindiana.org/) VM to test against, since I don't have access to an actual Solaris system. No dice. – larsks Feb 05 '21 at 01:12
  • 1
    I simply changed from `unarchive` module to `shell: unzip -d ` and it now works fine @larsks!! – Ashar Feb 05 '21 at 07:41
  • @Ashar I'm glad to hear a simple fix worked for you; feel free to add your own solution and accept it so others know your question is resolved. Also, don't forget to add `args: {creates: "/web/bea_apps/applications/{{ domain_home }}/{{ item }}/CURRENT/UAT-04022021_01/canv.ear"}` (or whatever) to preserve the idempotency of your `shell:` task – mdaniel Feb 06 '21 at 19:11

0 Answers0