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.
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
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.
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 but it didn’t have many specifics.
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)
win_acl - Access Control (Adding/Denying rules) for Users/Groups (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)
win_zip - Zipping files/directories (https://github.com/ansible/ansible-modules-extras/pull/177)
win_unzip - Unzipping compressed files/directories (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) and add it to a the root directory (where you run all your playbooks) in a library directory. Ansible will find them.
Cheers,
Phil
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.
and in case you need this one:
win_fw - Firewall management (https://github.com/ansible/ansible-modules-extras/pull/318)
Thank you for all of these! I am on Linux side as well and am working with Windows teams to automate their infrastructure.