Score:0

How to upload a zip file to a URL with Ansible on Windows?

gb flag

I am attempting to upload a zip file to a URL using Ansible on a Windows 10 machine. I'm currently trying something like the below:

    - name: Get zip file contents for upload
      slurp: 
        src: 'bundle.zip'
      register: zip_contents
      no_log: true
    - name: Upload ZIP
      ansible.windows.win_uri:
        url_method: "PUT"
        url: "my-url.com/bundle.zip"
        body: "{{ zip_contents['content'] | b64decode }}"

However, this results in a corrupt file being uploaded that is twice the expected size. I have tried to encode and decode a zip on my local to make sure this would work, and that seems fine. The above block works with other filetypes, like xml and json.

What is the best way to do this?

inframan avatar
cn flag
According to ansible doc and github issues there's no limitation about working on zip file (and didn't find any example elsewhere). It seems like slurp doesn't like zip byte headers Dumb question : does your zip contains others zip files ? Also, your URL is hosted on a windows target that's right ?
inframan avatar
cn flag
Maybe this link may help you (same situation as yours) https://github.com/ansible/ansible-modules-extras/issues/2999
Score:0
gb flag

Since I was trying to upload to Artifactory specifically, I found a workaround using the jfrog CLi:

    - name: Upload ZIP
      ansible.windows.win_powershell:
        script: |
          jfrog rt u 'bundle.zip' 'my-repo/bundle.zip'

However I would love a more native Ansible solution if one exists.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.