-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwin_s3.py
111 lines (105 loc) · 3.45 KB
/
win_s3.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
111
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2014, Phil Schwartz <[email protected]>
#
# 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_s3
version_added: ""
short_description: Upload and download from AWS S3
description:
- Uses AWS_SDK for Powershell. If the module is not found it will be downloaded. More Info: http://aws.amazon.com/powershell/. Uses the SDK, with either provided credentials or IAM role credentials on EC2 instances to upload and download files from S3. If provided, the credentials are set on the remote machine as the default profile (but only for this session).
options:
bucket:
description:
- S3 Bucket (Must exist)
required: true
default: null
aliases: []
key:
description:
- S3 Key
required: true
default: null
aliases: []
local:
description:
- Local file/directory to upload or download to.
required: yes
default: null
aliases: []
overwrite:
description:
- If true, download the file or directory even if it already exists on the host.
required: no
default: false
aliases: []
method:
description:
- S3 method to carry out. Upload: upload file or entire directory to s3. Download: download a file or directory from s3.
required: yes
choices:
- upload
- download
default: null
aliases: []
rm:
description:
- Remove the local file after upload?
required: no
choices:
- true
- false
default: false
aliases: []
access_key:
description:
- AWS_ACCESS_KEY_ID: Not required if there are credentials configured on the machine, or if the machine is an ec2 instance with an IAM role.
required: no
default: none
aliases: []
secret_key:
description:
- AWS_SECRET_ACCESS_KEY: Not required if there are credentials configured on the machine, or if the machine is an ec2 instance with an IAM role.
required: no
default: none
aliases: []
author: Phil Schwartz
'''
EXAMPLES = '''
# Upload a local file to S3
$ ansible -i hosts -m win_s3 -a "bucket=server_logs key=QA/WebServer/2015-1-1.App.log local=C:\inetpub\wwwroot\Logs\log.log method=upload rm=true access_key=EXAMPLE secret_key=EXAMPLE" all
# Download an entire directory from S3
$ ansible -i hosts -m win_s3 -a "bucket=apps key=My/Web/APP/ local=C:\Users\Me\WebApp method=download access_key=EXAMPLE secret_key=EXAMPLE" all
# Playbook example
---
- name: Download Application Zip from S3
hosts: all
gather_facts: false
tasks:
- name: Download app
win_s3:
bucket: 'app_deploys'
key: 'app/latest/Application.zip'
method: 'download'
overwrite: true
local: 'C:\Applications\\'
access_key: 'EXAMPLECRED'
secret_key: 'EXAMPLESECRET'
'''