2014-12-30 14:42:00 +00:00
#!/usr/bin/python
# -*- coding: utf-8 -*-
2015-06-18 21:15:15 +00:00
# (c) 2015, Phil Schwartz <schwartzmx@gmail.com>
2014-12-30 14:42:00 +00:00
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# this is a windows documentation stub. actual code lives in the .ps1
# file of the same name
2016-12-06 10:35:25 +00:00
ANSIBLE_METADATA = { ' status ' : [ ' preview ' ] ,
' supported_by ' : ' community ' ,
' version ' : ' 1.0 ' }
2017-01-19 01:57:33 +00:00
DOCUMENTATION = r '''
2014-12-30 14:42:00 +00:00
- - -
module : win_unzip
2015-07-18 03:14:18 +00:00
version_added : " 2.0 "
short_description : Unzips compressed files and archives on the Windows node
2014-12-30 14:42:00 +00:00
description :
2017-01-20 16:14:06 +00:00
- Unzips compressed files and archives .
- Supports . zip files natively
- Supports other formats supported by the Powershell Community Extensions ( PSCX ) module ( basically everything 7 zip supports )
requires :
- PSCX
2014-12-30 14:42:00 +00:00
options :
2015-01-11 19:03:26 +00:00
src :
2014-12-30 14:42:00 +00:00
description :
2015-01-11 19:03:26 +00:00
- File to be unzipped ( provide absolute path )
2014-12-30 14:42:00 +00:00
required : true
dest :
description :
2014-12-30 15:54:22 +00:00
- Destination of zip file ( provide absolute path of directory ) . If it does not exist , the directory will be created .
2014-12-30 14:42:00 +00:00
required : true
rm :
description :
- Remove the zip file , after unzipping
required : no
2015-01-11 19:03:26 +00:00
choices :
- true
- false
- yes
- no
2014-12-30 14:42:00 +00:00
default : false
2015-01-11 19:03:26 +00:00
recurse :
description :
- Recursively expand zipped files within the src file .
required : no
default : false
choices :
- true
- false
- yes
- no
2015-06-22 23:51:58 +00:00
creates :
2014-12-30 14:42:00 +00:00
description :
2015-06-22 23:51:58 +00:00
- If this file or directory exists the specified src will not be extracted .
required : no
default : null
2017-01-20 16:14:06 +00:00
notes :
- For extracting any compression types other than . zip , the PowerShellCommunityExtensions ( PSCX ) Module is required . This module ( in conjunction with PSCX ) has the ability to recursively unzip files within the src zip file provided and also functionality for many other compression types . If the destination directory does not exist , it will be created before unzipping the file . Specifying rm parameter will force removal of the src file after extraction .
2016-12-08 14:38:05 +00:00
author : Phil Schwartz
2014-12-30 14:42:00 +00:00
'''
2016-06-04 17:47:42 +00:00
EXAMPLES = r '''
2014-12-30 14:42:00 +00:00
# This unzips a library that was downloaded with win_get_url, and removes the file after extraction
2017-01-07 16:50:10 +00:00
# $ ansible -i hosts -m win_unzip -a "src=C:\\LibraryToUnzip.zip dest=C:\\Lib rm=true" all
2014-12-30 14:42:00 +00:00
# Playbook example
2015-01-11 19:03:26 +00:00
# Simple unzip
- - -
- name : Unzip a bz2 ( BZip ) file
win_unzip :
2017-01-07 16:50:10 +00:00
src : C : \Users \Phil \Logs . bz2
dest : C : \Users \Phil \OldLogs
creates : C : \Users \Phil \OldLogs
2015-01-11 19:03:26 +00:00
# This playbook example unzips a .zip file and recursively decompresses the contained .gz files and removes all unneeded compressed files after completion.
- name : Unzip ApplicationLogs . zip and decompress all GZipped log files
hosts : all
gather_facts : false
tasks :
- name : Recursively decompress GZ files in ApplicationLogs . zip
win_unzip :
src : C : \Downloads \ApplicationLogs . zip
dest : C : \Application \Logs
recurse : yes
rm : true
2015-06-18 21:15:15 +00:00
# Install PSCX to use for extracting a gz file
2017-02-07 21:39:24 +00:00
- name : Grab PSCX msi
win_get_url :
url : http : / / download - codeplex . sec . s - msft . com / Download / Release ? ProjectName = pscx & DownloadId = 923562 & FileTime = 130585918034470000 & Build = 20959
dest : C : \pscx . msi
- name : Install PSCX
win_msi :
path : C : \pscx . msi
- name : Unzip gz log
win_unzip :
src : C : \Logs \application - error - logs . gz
dest : C : \ExtractedLogs \application - error - logs
2014-12-30 14:42:00 +00:00
'''