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
11175781
Commit
11175781
authored
Nov 18, 2012
by
Daniel Hokka Zakrisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use slurp for fetch is sudo is enabled and needed
Fixes #1020.
parent
99a0ebca
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
6 deletions
+24
-6
lib/ansible/runner/action_plugins/fetch.py
+17
-6
lib/ansible/utils/__init__.py
+7
-0
No files found.
lib/ansible/runner/action_plugins/fetch.py
View file @
11175781
...
...
@@ -20,6 +20,7 @@ import pwd
import
random
import
traceback
import
tempfile
import
base64
import
ansible.constants
as
C
from
ansible
import
utils
...
...
@@ -43,11 +44,6 @@ class ActionModule(object):
results
=
dict
(
failed
=
True
,
msg
=
"src and dest are required"
)
return
ReturnData
(
conn
=
conn
,
result
=
results
)
# apply templating to source argument
source
=
utils
.
template
(
self
.
runner
.
basedir
,
source
,
inject
)
# apply templating to dest argument
dest
=
utils
.
template
(
self
.
runner
.
basedir
,
dest
,
inject
)
# files are saved in dest dir, with a subdir for each host, then the filename
dest
=
"
%
s/
%
s/
%
s"
%
(
utils
.
path_dwim
(
self
.
runner
.
basedir
,
dest
),
conn
.
host
,
source
)
dest
=
dest
.
replace
(
"//"
,
"/"
)
...
...
@@ -55,6 +51,16 @@ class ActionModule(object):
# calculate md5 sum for the remote file
remote_md5
=
self
.
runner
.
_remote_md5
(
conn
,
tmp
,
source
)
# use slurp if sudo and permissions are lacking
remote_data
=
None
if
remote_md5
in
(
'1'
,
'2'
)
and
self
.
runner
.
sudo
:
slurpres
=
self
.
runner
.
_execute_module
(
conn
,
tmp
,
'slurp'
,
'src=
%
s'
%
source
,
inject
=
inject
)
if
slurpres
.
is_successful
():
if
slurpres
.
result
[
'encoding'
]
==
'base64'
:
remote_data
=
base64
.
b64decode
(
slurpres
.
result
[
'content'
])
if
remote_data
is
not
None
:
remote_md5
=
utils
.
md5s
(
remote_data
)
# these don't fail because you may want to transfer a log file that possibly MAY exist
# but keep going to fetch other log files
if
remote_md5
==
'0'
:
...
...
@@ -76,7 +82,12 @@ class ActionModule(object):
os
.
makedirs
(
os
.
path
.
dirname
(
dest
))
# fetch the file and check for changes
conn
.
fetch_file
(
source
,
dest
)
if
remote_data
is
None
:
conn
.
fetch_file
(
source
,
dest
)
else
:
f
=
open
(
dest
,
'w'
)
f
.
write
(
remote_data
)
f
.
close
()
new_md5
=
utils
.
md5
(
dest
)
if
new_md5
!=
remote_md5
:
result
=
dict
(
failed
=
True
,
md5sum
=
new_md5
,
msg
=
"md5 mismatch"
,
file
=
source
)
...
...
lib/ansible/utils/__init__.py
View file @
11175781
...
...
@@ -261,6 +261,13 @@ def parse_kv(args):
options
[
k
]
=
v
return
options
def
md5s
(
data
):
''' Return MD5 hex digest of data. '''
digest
=
_md5
()
digest
.
update
(
data
)
return
digest
.
hexdigest
()
def
md5
(
filename
):
''' Return MD5 hex digest of local file, or None if file is not present. '''
...
...
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