Debian Codegraph @

ansible_collections/community/windows/plugins/modules/win_unzip.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2015, Phil Schwartz <[email protected]>
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 DOCUMENTATION = r'''
8 ---
9 module: win_unzip
10 short_description: Unzips compressed files and archives on the Windows node
11 description:
12 - Unzips compressed files and archives.
13 - Supports .zip files natively.
14 - Supports other formats supported by the Powershell Community Extensions (PSCX) module (basically everything 7zip supports).
15 - For non-Windows targets, use the M(ansible.builtin.unarchive) module instead.
16 requirements:
17 - PSCX
18 options:
19 src:
20 description:
21 - File to be unzipped (provide absolute path).
22 type: path
23 required: yes
24 dest:
25 description:
26 - Destination of zip file (provide absolute path of directory). If it does not exist, the directory will be created.
27 type: path
28 required: yes
29 delete_archive:
30 description:
31 - Remove the zip file, after unzipping.
32 type: bool
33 default: no
34 aliases: [ rm ]
35 recurse:
36 description:
37 - Recursively expand zipped files within the src file.
38 - Setting to a value of C(yes) requires the PSCX module to be installed.
39 type: bool
40 default: no
41 creates:
42 description:
43 - If this file or directory exists the specified src will not be extracted.
44 type: path
45 password:
46 description:
47 - If a zip file is encrypted with password.
48 - Passing a value to a password parameter requires the PSCX module to be installed.
49 notes:
50 - This module is not really idempotent, it will extract the archive every time, and report a change.
51 - For extracting any compression types other than .zip, the PowerShellCommunityExtensions (PSCX) Module is required. This module (in conjunction with PSCX)
52 has the ability to recursively unzip files within the src zip file provided and also functionality for many other compression types. If the destination
53 directory does not exist, it will be created before unzipping the file. Specifying rm parameter will force removal of the src file after extraction.
54 seealso:
55 - module: ansible.builtin.unarchive
56 author:
57 - Phil Schwartz (@schwartzmx)
58 '''
59
60 EXAMPLES = r'''
61 # This unzips a library that was downloaded with win_get_url, and removes the file after extraction
62 # $ ansible -i hosts -m win_unzip -a "src=C:\LibraryToUnzip.zip dest=C:\Lib remove=yes" all
63
64 - name: Unzip a bz2 (BZip) file
65 community.windows.win_unzip:
66 src: C:\Users\Phil\Logs.bz2
67 dest: C:\Users\Phil\OldLogs
68 creates: C:\Users\Phil\OldLogs
69
70 - name: Unzip gz log
71 community.windows.win_unzip:
72 src: C:\Logs\application-error-logs.gz
73 dest: C:\ExtractedLogs\application-error-logs
74
75 # Unzip .zip file, recursively decompresses the contained .gz files and removes all unneeded compressed files after completion.
76 - name: Recursively decompress GZ files in ApplicationLogs.zip
77 community.windows.win_unzip:
78 src: C:\Downloads\ApplicationLogs.zip
79 dest: C:\Application\Logs
80 recurse: true
81 delete_archive: true
82
83 - name: Install PSCX
84 community.windows.win_psmodule:
85 name: Pscx
86 state: present
87
88 - name: Unzip .7z file which is password encrypted
89 community.windows.win_unzip:
90 src: C:\Downloads\ApplicationLogs.7z
91 dest: C:\Application\Logs
92 password: abcd
93 delete_archive: true
94 '''
95
96 RETURN = r'''
97 dest:
98 description: The provided destination path
99 returned: always
100 type: str
101 sample: C:\ExtractedLogs\application-error-logs
102 removed:
103 description: Whether the module did remove any files during task run
104 returned: always
105 type: bool
106 sample: true
107 src:
108 description: The provided source path
109 returned: always
110 type: str
111 sample: C:\Logs\application-error-logs.gz
112 '''