Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
21235073
Commit
21235073
authored
Jun 18, 2013
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'sha256' of
git://github.com/jlund/ansible
into devel
Conflicts: library/network/get_url
parents
92754065
37f15d02
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
13 deletions
+60
-13
lib/ansible/module_common.py
+21
-4
library/network/get_url
+39
-9
No files found.
lib/ansible/module_common.py
View file @
21235073
...
...
@@ -86,12 +86,19 @@ try:
except ImportError:
pass
HAVE_HASHLIB=False
try:
from hashlib import md5 as _md5
HAVE_HASHLIB=True
except ImportError:
from md5 import md5 as _md5
try:
from hashlib import sha256 as _sha256
except ImportError:
pass
try:
from systemd import journal
has_journal = True
except ImportError:
...
...
@@ -787,13 +794,13 @@ class AnsibleModule(object):
or stat.S_IXGRP & os.stat(path)[stat.ST_MODE]
or stat.S_IXOTH & os.stat(path)[stat.ST_MODE])
def
md5(self, filename
):
''' Return
MD5 hex digest of local file
, or None if file is not present. '''
def
digest_from_file(self, filename, digest_method
):
''' Return
hex digest of local file for a given digest_method
, or None if file is not present. '''
if not os.path.exists(filename):
return None
if os.path.isdir(filename):
self.fail_json(msg="attempted to take
md5
sum of directory:
%
s"
%
filename)
digest =
_md5()
self.fail_json(msg="attempted to take
check
sum of directory:
%
s"
%
filename)
digest =
digest_method
blocksize = 64 * 1024
infile = open(filename, 'rb')
block = infile.read(blocksize)
...
...
@@ -803,6 +810,16 @@ class AnsibleModule(object):
infile.close()
return digest.hexdigest()
def md5(self, filename):
''' Return MD5 hex digest of local file using digest_from_file(). '''
return self.digest_from_file(filename, _md5())
def sha256(self, filename):
''' Return SHA-256 hex digest of local file using digest_from_file(). '''
if not HAVE_HASHLIB:
self.fail_json(msg="SHA-256 checksums require hashlib, which is available in Python 2.5 and higher")
return self.digest_from_file(filename, _sha256())
def backup_local(self, fn):
'''make a date-marked backup of the specified file, return True or False on success or failure'''
# backups named basename-YYYY-MM-DD@HH:MM~
...
...
library/network/get_url
View file @
21235073
...
...
@@ -33,7 +33,7 @@ description:
server I(must) have direct access to the remote resource.
- By default, if an environment variable C(<protocol>_proxy) is set on
the target host, requests will be sent through that proxy. This
behaviour can be overriden by setting a variable for this task
behaviour can be overrid
d
en by setting a variable for this task
(see `setting the environment
<http://ansible.cc/docs/playbooks2.html#setting-the-environment-and-working-with-proxies>`_),
or by using the use_proxy option.
...
...
@@ -53,19 +53,27 @@ options:
default: null
force:
description:
-
i
f C(yes), will download the file every time and replace the
-
I
f C(yes), will download the file every time and replace the
file if the contents change. If C(no), the file will only be downloaded if
the destination does not exist. Generally should be C(yes) only for small
local files.
prior to 0.6, acts if C(yes) by
default.
local files.
Prior to 0.6, this module behaved as if C(yes) was the
default.
version_added: "0.7"
required: false
choices: [ "yes", "no" ]
default: "no"
aliases: [ "thirsty" ]
sha256sum:
description:
- If a SHA-256 checksum is passed to this parameter, the digest of the
destination file will be calculated after it is downloaded to ensure
its integrity and verify that the transfer completed successfully.
version_added: "1.3"
required: false
default: null
use_proxy:
description:
- if C(no), it will not use a proxy, even if one is defined
by
in
an environment variable on the target hosts.
- if C(no), it will not use a proxy, even if one is defined
in
an environment variable on the target hosts.
required: false
default: 'yes'
choices: ['yes', 'no']
...
...
@@ -81,20 +89,30 @@ author: Jan-Piet Mens
'''
EXAMPLES
=
'''
- get_url: url=http://example.com/path/file.conf dest=/etc/foo.conf mode=0440
<<<<<<< HEAD
- name: download foo.conf
get_url: url=http://example.com/path/file.conf dest=/etc/foo.conf mode=0440
- name: download file with sha256 check
get_url: url=http://example.com/path/file.conf dest=/etc/foo.conf sha256sum=b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c
'''
try
:
import
hashlib
HAS_HASHLIB
=
True
except
ImportError
:
HAS_HASHLIB
=
False
HAS_URLLIB2
=
True
try
:
import
urllib2
HAS_URLLIB2
=
True
except
ImportError
:
HAS_URLLIB2
=
False
HAS_URLPARSE
=
True
try
:
import
urlparse
import
socket
HAS_URLPARSE
=
True
except
ImportError
:
HAS_URLPARSE
=
False
...
...
@@ -217,6 +235,7 @@ def main():
url
=
dict
(
required
=
True
),
dest
=
dict
(
required
=
True
),
force
=
dict
(
default
=
'no'
,
aliases
=
[
'thirsty'
],
type
=
'bool'
),
sha256sum
=
dict
(
default
=
''
),
use_proxy
=
dict
(
default
=
'yes'
,
type
=
'bool'
)
),
add_file_common_args
=
True
...
...
@@ -225,6 +244,7 @@ def main():
url
=
module
.
params
[
'url'
]
dest
=
os
.
path
.
expanduser
(
module
.
params
[
'dest'
])
force
=
module
.
params
[
'force'
]
sha256sum
=
module
.
params
[
'sha256sum'
]
use_proxy
=
module
.
params
[
'use_proxy'
]
if
os
.
path
.
isdir
(
dest
):
...
...
@@ -273,6 +293,16 @@ def main():
else
:
changed
=
False
# Check the digest of the destination file and ensure that it matches the
# sha256sum parameter if it is present
if
sha256sum
!=
''
:
if
not
HAS_HASHLIB
:
os
.
remove
(
dest
)
module
.
fail_json
(
msg
=
"The sha256sum parameter requires hashlib, which is available in Python 2.5 and higher"
)
if
sha256sum
!=
module
.
sha256
(
dest
):
os
.
remove
(
dest
)
module
.
fail_json
(
msg
=
"The SHA-256 checksum for
%
s did not match
%
s"
%
(
dest
,
sha256sum
))
os
.
remove
(
tmpsrc
)
# allow file attribute changes
...
...
@@ -283,7 +313,7 @@ def main():
# Mission complete
module
.
exit_json
(
url
=
url
,
dest
=
dest
,
src
=
tmpsrc
,
md5sum
=
md5sum_src
,
changed
=
changed
,
msg
=
info
.
get
(
'msg'
,
''
))
sha256sum
=
sha256sum
,
changed
=
changed
,
msg
=
info
.
get
(
'msg'
,
''
))
# this is magic, see lib/ansible/module_common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment