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
8220d576
Commit
8220d576
authored
Jul 07, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up md5 functions + make the fetch module stay happy if the remote file does not exist.
parent
b551eba6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
6 deletions
+40
-6
lib/ansible/runner/__init__.py
+24
-6
lib/ansible/utils.py
+16
-0
No files found.
lib/ansible/runner/__init__.py
View file @
8220d576
...
@@ -481,19 +481,20 @@ class Runner(object):
...
@@ -481,19 +481,20 @@ class Runner(object):
dest
=
dest
.
replace
(
"//"
,
"/"
)
dest
=
dest
.
replace
(
"//"
,
"/"
)
# compare old and new md5 for support of change hooks
# compare old and new md5 for support of change hooks
local_md5
=
None
local_md5
=
utils
.
local_md5
(
dest
)
if
os
.
path
.
exists
(
dest
):
remote_md5
=
self
.
_remote_md5
(
conn
,
tmp
,
source
)
local_md5
=
os
.
popen
(
"/usr/bin/md5sum
%(file)
s 2> /dev/null || /sbin/md5 -q
%(file)
s"
%
{
"file"
:
dest
})
.
read
()
.
split
()[
0
]
remote_md5
=
self
.
_low_level_exec_command
(
conn
,
"/usr/bin/md5sum
%(file)
s 2> /dev/null || /sbin/md5 -q
%(file)
s"
%
{
"file"
:
source
},
tmp
,
True
)
.
split
()[
0
]
if
remote_md5
!=
local_md5
:
if
remote_md5
==
'0'
:
result
=
dict
(
msg
=
"missing remote file"
,
changed
=
False
)
return
ReturnData
(
host
=
conn
.
host
,
result
=
result
)
elif
remote_md5
!=
local_md5
:
# create the containing directories, if needed
# create the containing directories, if needed
if
not
os
.
path
.
isdir
(
os
.
path
.
dirname
(
dest
)):
if
not
os
.
path
.
isdir
(
os
.
path
.
dirname
(
dest
)):
os
.
makedirs
(
os
.
path
.
dirname
(
dest
))
os
.
makedirs
(
os
.
path
.
dirname
(
dest
))
# fetch the file and check for changes
# fetch the file and check for changes
conn
.
fetch_file
(
source
,
dest
)
conn
.
fetch_file
(
source
,
dest
)
new_md5
=
os
.
popen
(
"/usr/bin/md5sum
%(file)
s 2> /dev/null || /sbin/md5 -q
%(file)
s"
%
{
"file"
:
dest
})
.
read
()
.
split
()[
0
]
new_md5
=
utils
.
local_md5
(
dest
)
if
new_md5
!=
remote_md5
:
if
new_md5
!=
remote_md5
:
result
=
dict
(
failed
=
True
,
msg
=
"md5 mismatch"
,
md5sum
=
new_md5
)
result
=
dict
(
failed
=
True
,
msg
=
"md5 mismatch"
,
md5sum
=
new_md5
)
return
ReturnData
(
host
=
conn
.
host
,
result
=
result
)
return
ReturnData
(
host
=
conn
.
host
,
result
=
result
)
...
@@ -723,6 +724,23 @@ class Runner(object):
...
@@ -723,6 +724,23 @@ class Runner(object):
# *****************************************************
# *****************************************************
def
_remote_md5
(
self
,
conn
,
tmp
,
path
):
'''
takes a remote md5sum without requiring python, and returns 0 if the
file does not exist
'''
test
=
"[[ -r
%
s ]]"
%
path
md5s
=
[
"(
%
s && /usr/bin/md5sum
%
s 2>/dev/null)"
%
(
test
,
path
),
"(
%
s && /sbin/md5sum -q
%
s 2>/dev/null)"
%
(
test
,
path
)
]
cmd
=
" || "
.
join
(
md5s
)
cmd
=
"
%
s || (echo
\"
0
%
s
\"
)"
%
(
cmd
,
path
)
remote_md5
=
self
.
_low_level_exec_command
(
conn
,
cmd
,
tmp
,
True
)
.
split
()[
0
]
return
remote_md5
# *****************************************************
def
_make_tmp_path
(
self
,
conn
):
def
_make_tmp_path
(
self
,
conn
):
''' make and return a temporary path on a remote box '''
''' make and return a temporary path on a remote box '''
...
...
lib/ansible/utils.py
View file @
8220d576
...
@@ -312,6 +312,22 @@ def parse_kv(args):
...
@@ -312,6 +312,22 @@ def parse_kv(args):
options
[
k
]
=
v
options
[
k
]
=
v
return
options
return
options
def
local_md5
(
file
):
''' compute local md5sum, return None if file is not present '''
cmd
=
"/usr/bin/md5sum
%
s 2> /dev/null || /sbin/md5 -q
%
s"
%
(
file
,
file
)
if
not
os
.
path
.
exists
(
file
):
return
None
else
:
c
=
os
.
popen
(
cmd
)
return
c
.
read
()
.
split
()[
0
]
####################################################################
# option handling code for /usr/bin/ansible and ansible-playbook
# below this line
# FIXME: move to seperate file
class
SortedOptParser
(
optparse
.
OptionParser
):
class
SortedOptParser
(
optparse
.
OptionParser
):
'''Optparser which sorts the options by opt before outputting --help'''
'''Optparser which sorts the options by opt before outputting --help'''
def
format_help
(
self
,
formatter
=
None
):
def
format_help
(
self
,
formatter
=
None
):
...
...
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