forked from ansible/ansible-modules-extras
/
win_zip.py
110 lines (103 loc) · 3.36 KB
/
win_zip.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2014, Phil Schwartz <schwartzmx@gmail.com>
#
# 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
DOCUMENTATION = '''
---
module: win_zip
version_added: ""
short_description: Zips file or directory on the Windows node
description:
- Zips the specified local file or directory on the Windows node. Depends on PSCX (PowerShell Community Extensions). PSCX is downloaded and installed if it is not found. If found it imports the module and continues. For information on PSCX visit https://pscx.codeplex.com/.
options:
src:
description:
- Local file or directory (provide absolute path)
required: true
default: null
aliases: []
dest:
description:
- Destination of compressed zip file (provide absolute path) and name of desired output file. If a .zip extension is not present, it will be detected and added automatically. The path specified must exist, the basename doesn't need to exist.
required: true
default: null
aliases: []
type:
description:
- Type of compression method to use.
required: false
default: zip
choices:
- zip
- bzip
- tar
- gzip
aliases: []
creates:
description:
- If the specified file or directory exists then no changes will be made.
required: false
aliases: []
rm:
description:
- Remove the (unzipped) src file, after zipping
required: no
choices:
- true
- false
- yes
- no
default: false
aliases: []
author: Phil Schwartz
'''
EXAMPLES = '''
# Zips directory on Windows Host and saves as SRC.zip
$ ansible -i hosts -m win_zip -a "src=C:\\Users\\Administrator\\SRC dest=C:\\Users\\Administrator\\SRC.zip rm=true" all
# Zips a file on Windows Host and saves as xfile.txt.zip
$ ansible -i hosts -m win_zip -a "src=C:\\Users\\Phil\\xfile.txt dest=C:\\xfile.txt" all
# BZip all files in a directory, and move them all into a new directory, and removes all files within the src folder
$ ansible -i hosts -m win_zip -a "src=C:\\Logs\\ dest=C:\\UploadFolder type=bzip rm=true"
# Playbook example
---
- name: Zip Logs
hosts: all
gather_facts: false
tasks:
- name: win_zip the inet log directory and then remove the src directory after completion
win_zip:
src: 'C:\\inetpub\\wwwroot\\Logs'
dest: 'C:\\Logs\1-1-15.ServerLogs.zip'
rm: true
---
- name: Tar a folder, and then GZip the Tar
hosts: all
tasks:
- name: Tar folder
win_zip:
src: 'C:\\folder\\to\\tar'
dest: 'C:\\TA.tar'
type: tar
creates: 'C:\\TA.tar'
- name: GZip Tatar
win_zip:
src: 'C:\\TA.tar'
dest: 'C:\\Totz.gz'
type: gzip
'''