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
affb6641
Commit
affb6641
authored
Feb 25, 2015
by
Toshio Kuratomi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Port fix for #10300 to v2
parent
e146245a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
6 deletions
+33
-6
v2/ansible/plugins/action/template.py
+26
-6
v2/ansible/plugins/shell/sh.py
+7
-0
No files found.
v2/ansible/plugins/action/template.py
View file @
affb6641
...
@@ -26,6 +26,27 @@ class ActionModule(ActionBase):
...
@@ -26,6 +26,27 @@ class ActionModule(ActionBase):
TRANSFERS_FILES
=
True
TRANSFERS_FILES
=
True
def
get_checksum
(
self
,
tmp
,
dest
,
try_directory
=
False
,
source
=
None
):
remote_checksum
=
self
.
_remote_checksum
(
tmp
,
dest
)
if
remote_checksum
in
(
'0'
,
'2'
,
'3'
,
'4'
):
# Note: 1 means the file is not present which is fine; template
# will create it. 3 means directory was specified instead of file
if
try_directory
and
remote_checksum
==
'3'
and
source
:
base
=
os
.
path
.
basename
(
source
)
dest
=
os
.
path
.
join
(
dest
,
base
)
remote_checksum
=
self
.
get_checksum
(
tmp
,
dest
,
try_directory
=
False
)
if
remote_checksum
not
in
(
'0'
,
'2'
,
'3'
,
'4'
):
return
remote_checksum
result
=
dict
(
failed
=
True
,
msg
=
"failed to checksum remote file."
" Checksum error code:
%
s"
%
remote_checksum
)
return
result
return
remote_checksum
def
run
(
self
,
tmp
=
None
,
task_vars
=
dict
()):
def
run
(
self
,
tmp
=
None
,
task_vars
=
dict
()):
''' handler for template operations '''
''' handler for template operations '''
...
@@ -84,12 +105,11 @@ class ActionModule(ActionBase):
...
@@ -84,12 +105,11 @@ class ActionModule(ActionBase):
except
Exception
,
e
:
except
Exception
,
e
:
return
dict
(
failed
=
True
,
msg
=
type
(
e
)
.
__name__
+
": "
+
str
(
e
))
return
dict
(
failed
=
True
,
msg
=
type
(
e
)
.
__name__
+
": "
+
str
(
e
))
local_checksum
=
checksum_s
(
resultant
)
local_checksum
=
utils
.
checksum_s
(
resultant
)
remote_checksum
=
self
.
_remote_checksum
(
tmp
,
dest
)
remote_checksum
=
self
.
get_checksum
(
tmp
,
dest
,
not
directory_prepended
,
source
=
source
)
if
isinstance
(
remote_checksum
,
dict
):
if
remote_checksum
in
(
'0'
,
'2'
,
'3'
,
'4'
):
# Error from remote_checksum is a dict. Valid return is a str
# Note: 1 means the file is not present which is fine; template will create it
return
remote_checksum
return
dict
(
failed
=
True
,
msg
=
"failed to checksum remote file. Checksum error code:
%
s"
%
remote_checksum
)
if
local_checksum
!=
remote_checksum
:
if
local_checksum
!=
remote_checksum
:
# if showing diffs, we need to get the remote value
# if showing diffs, we need to get the remote value
...
...
v2/ansible/plugins/shell/sh.py
View file @
affb6641
...
@@ -96,6 +96,13 @@ class ShellModule(object):
...
@@ -96,6 +96,13 @@ class ShellModule(object):
# 0. This logic is added to the end of the cmd at the bottom of this
# 0. This logic is added to the end of the cmd at the bottom of this
# function.
# function.
# Return codes:
# checksum: success!
# 0: Unknown error
# 1: Remote file does not exist
# 2: No read permissions on the file
# 3: File is a directory
# 4: No python interpreter
test
=
"rc=flag; [ -r
\'
%(p)
s
\'
] || rc=2; [ -f
\'
%(p)
s
\'
] || rc=1; [ -d
\'
%(p)
s
\'
] && rc=3;
%(i)
s -V 2>/dev/null || rc=4; [ x
\"
$rc
\"
!=
\"
xflag
\"
] && echo
\"
${rc}
\"\'
%(p)
s
\'
&& exit 0"
%
dict
(
p
=
path
,
i
=
python_interp
)
test
=
"rc=flag; [ -r
\'
%(p)
s
\'
] || rc=2; [ -f
\'
%(p)
s
\'
] || rc=1; [ -d
\'
%(p)
s
\'
] && rc=3;
%(i)
s -V 2>/dev/null || rc=4; [ x
\"
$rc
\"
!=
\"
xflag
\"
] && echo
\"
${rc}
\"\'
%(p)
s
\'
&& exit 0"
%
dict
(
p
=
path
,
i
=
python_interp
)
csums
=
[
csums
=
[
"(
%
s -c 'import hashlib; BLOCKSIZE = 65536; hasher = hashlib.sha1();
\n
afile = open(
\"
%
s
\"
,
\"
rb
\"
)
\n
buf = afile.read(BLOCKSIZE)
\n
while len(buf) > 0:
\n\t
hasher.update(buf)
\n\t
buf = afile.read(BLOCKSIZE)
\n
afile.close()
\n
print(hasher.hexdigest())' 2>/dev/null)"
%
(
python_interp
,
path
),
# Python > 2.4 (including python3)
"(
%
s -c 'import hashlib; BLOCKSIZE = 65536; hasher = hashlib.sha1();
\n
afile = open(
\"
%
s
\"
,
\"
rb
\"
)
\n
buf = afile.read(BLOCKSIZE)
\n
while len(buf) > 0:
\n\t
hasher.update(buf)
\n\t
buf = afile.read(BLOCKSIZE)
\n
afile.close()
\n
print(hasher.hexdigest())' 2>/dev/null)"
%
(
python_interp
,
path
),
# Python > 2.4 (including python3)
...
...
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