# Ansible windows unzip

**URL:** <https://forum.ansible.com/t/ansible-windows-unzip/17448>\
**Category:** Ansible Developer\
**Tags:** windows\
**Created:** [February 4, 2015, 8:19pm UTC](https://forum.ansible.com/t/ansible-windows-unzip/17448 "2015-02-04T20:19:01Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Perzel](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@Michael\_Perzel](https://forum.ansible.com/u/Michael_Perzel)\
**Post date:** [February 4, 2015, 8:19pm UTC](https://forum.ansible.com/t/ansible-windows-unzip/17448/1 "2015-02-04T20:19:01Z")

</div>

I’ve been working on orchestrating our windows hosts with ansible and had the need to be able to unzip files. Since the unarchive module was \*nix only I wrote an unzip.ps1/py module. I’d love to have feedback on it. I had some issues using the helper powershell methods. For example Fail-Json $result “error message” gave me errors parsing the json. So I aggregated the output of the module into a variable called output.

The source is available at [https://github.com/perzizzle/ansible/blob/master/library/unzip.ps1](https://github.com/perzizzle/ansible/blob/master/library/unzip.ps1).

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [February 9, 2015, 7:04am UTC](https://forum.ansible.com/t/ansible-windows-unzip/17448/2 "2015-02-09T07:04:28Z")

</div>

Hi,

Thanks for sharing your code.

Are you thinking of submitting a pull request?

I too have a win unzip module which I’ve been working on but I’m not ready to share yet.

Did you try coding the Fail-Json calls like this (creating a new object rather than re-using $result)?

`Fail-Json (New-Object psobject) "failure message goes here";`

The powershell code seems to support ‘include’ and ‘exclude’ parameters, but they aren’t mentioned in the docs. I can’t test your code right now but if they are optional params, and you are going to create a PR I think they should be documented.

Looking back at the code I have so far, I’ve tried to port the parts I can of the unarchive module, so I have a a ‘creates’ parameter which lets you specify file that, if it exists, the unzip doesn’t happen again and I’ve made a start on supporting ’ a ‘copy’ option as well, so the zip can be copied from ansible master to windows guest. For copy to work I need to port the unarchive action plugin and the win\_copy module which is pending V2 (mostly because I believe V2 will allow action plugins to share common code).

Would you be interested in looking through what I’ve got with a view to creating a PR?

All the best,

Jon

---

<div class="post-metadata">

**Author:** ![Michael\_Perzel](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@Michael\_Perzel](https://forum.ansible.com/u/Michael_Perzel)\
**Post date:** [February 9, 2015, 2:31pm UTC](https://forum.ansible.com/t/ansible-windows-unzip/17448/3 "2015-02-09T14:31:19Z")

</div>

Thanks for the feedback. I can add documentation for include/exclude (you are correct they are optional). Its a relatively simple task to add creates so I can do that as well and test to see if returning a new object fixes my parsing issues. I wasn’t planning on tackling copy, I’ve read about the “win\_copy” module in these forums and thought I’d just wait for that to be ready. Currently, I’m using win\_get\_url to copy files from a linux to windows machine. I was planning on doing a pull request but thought I’d elicit some feedback here first in case someone else had already done it.

---

<div class="post-metadata">

**Author:** ![Michael\_Perzel](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@Michael\_Perzel](https://forum.ansible.com/u/Michael_Perzel)\
**Post date:** [February 9, 2015, 8:58pm UTC](https://forum.ansible.com/t/ansible-windows-unzip/17448/4 "2015-02-09T20:58:07Z")

</div>

Your suggestion for putting Fail-Json messages into a new object worked. I’ve updated the source with documentation on include/exclude, “creates” functionality and the new Fail-Json object. I’ve never submitted a pull request to ansible so if anyone has a good link on how to do so let me know. I’ve read this page [http://docs.ansible.com/developing\_modules.html](http://docs.ansible.com/developing_modules.html) but it didn’t have many specifics.

---

<div class="post-metadata">

**Author:** ![Michael\_Perzel](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@Michael\_Perzel](https://forum.ansible.com/u/Michael_Perzel)\
**Post date:** [February 23, 2015, 3:00pm UTC](https://forum.ansible.com/t/ansible-windows-unzip/17448/5 "2015-02-23T15:00:42Z")

</div>

I created pull request [https://github.com/ansible/ansible-modules-extras/pull/277](https://github.com/ansible/ansible-modules-extras/pull/277)

---

<div class="post-metadata">

**Author:** ![Phil\_Schwartz](https://avatars.discourse-cdn.com/v4/letter/p/e47774/32.png) [@Phil\_Schwartz](https://forum.ansible.com/u/Phil_Schwartz)\
**Post date:** [February 24, 2015, 9:43pm UTC](https://forum.ansible.com/t/ansible-windows-unzip/17448/6 "2015-02-24T21:43:01Z")

</div>

Since you guys seem to also use ansible with Windows, here are some of my PRs that have been sitting in ansible-modules-extras incase you all would like to get some use out of them. (including a win\_unzip module)

win\_host - Domain Joining/Unjoinin ([https://github.com/ansible/ansible-modules-extras/pull/213](https://github.com/ansible/ansible-modules-extras/pull/213))  
win\_acl - Access Control (Adding/Denying rules) for Users/Groups ([https://github.com/ansible/ansible-modules-extras/pull/200](https://github.com/ansible/ansible-modules-extras/pull/200))  
win\_s3 - Downloading/Uploading to and from AWS S3 ([https://github.com/ansible/ansible-modules-extras/pull/180](https://github.com/ansible/ansible-modules-extras/pull/180))  
win\_zip - Zipping files/directories ([https://github.com/ansible/ansible-modules-extras/pull/177](https://github.com/ansible/ansible-modules-extras/pull/177))  
win\_unzip - Unzipping compressed files/directories ([https://github.com/ansible/ansible-modules-extras/pull/174](https://github.com/ansible/ansible-modules-extras/pull/174))

If you run into any problems (if you use them), please let me know.

To make it easier, if you want just clone my repo ([http://github.com/schwartzmx/ansible-module-devel](http://github.com/schwartzmx/ansible-module-devel)) and add it to a the root directory (where you run all your playbooks) in a library directory. Ansible will find them.

Cheers,

Phil

---

<div class="post-metadata">

**Author:** ![Corwin\_Brown](https://avatars.discourse-cdn.com/v4/letter/c/d6d6ee/32.png) [@Corwin\_Brown](https://forum.ansible.com/u/Corwin_Brown)\
**Post date:** [March 8, 2015, 9:14pm UTC](https://forum.ansible.com/t/ansible-windows-unzip/17448/7 "2015-03-08T21:14:30Z")

</div>

You sir, are a godsend. I hope they merge your modules soon! I’m a Linux admin who’s trying to push Ansible to the Windows half of our infrastructure, and a lack of unzip was one of the bullets used to shoot down the idea.

---

<div class="post-metadata">

**Author:** ![Timothy\_Vandenbrande](https://avatars.discourse-cdn.com/v4/letter/t/7ab992/32.png) [@Timothy\_Vandenbrande](https://forum.ansible.com/u/Timothy_Vandenbrande)\
**Post date:** [March 17, 2015, 9:32am UTC](https://forum.ansible.com/t/ansible-windows-unzip/17448/8 "2015-03-17T09:32:05Z")

</div>

and in case you need this one:  
win\_fw - Firewall management ([https://github.com/ansible/ansible-modules-extras/pull/318](https://github.com/ansible/ansible-modules-extras/pull/318))

---

<div class="post-metadata">

**Author:** ![John-Paul\_Herold](https://avatars.discourse-cdn.com/v4/letter/j/f475e1/32.png) [@John-Paul\_Herold](https://forum.ansible.com/u/John-Paul_Herold)\
**Post date:** [March 26, 2015, 9:21pm UTC](https://forum.ansible.com/t/ansible-windows-unzip/17448/9 "2015-03-26T21:21:44Z")

</div>

Thank you for all of these! I am on Linux side as well and am working with Windows teams to automate their infrastructure.
