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
3cc564c1
Commit
3cc564c1
authored
Aug 11, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'devel' of
https://github.com/SleeplessAnnoyedNerd/ansible
into devel
parents
d1ad1d25
ac44c36e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
11 deletions
+35
-11
lib/ansible/runner/__init__.py
+2
-2
lib/ansible/runner/connection/ssh.py
+2
-6
lib/ansible/utils.py
+31
-3
No files found.
lib/ansible/runner/__init__.py
View file @
3cc564c1
...
...
@@ -655,7 +655,7 @@ class Runner(object):
cmd
=
" || "
.
join
(
md5s
)
cmd
=
"
%
s;
%
s || (echo
\"
${rc}
%
s
\"
)"
%
(
test
,
cmd
,
path
)
return
self
.
_low_level_exec_command
(
conn
,
cmd
,
tmp
,
sudoable
=
False
)
.
split
()[
0
]
return
utils
.
last_non_blank_line
(
self
.
_low_level_exec_command
(
conn
,
cmd
,
tmp
,
sudoable
=
False
))
# *****************************************************
...
...
@@ -675,7 +675,7 @@ class Runner(object):
cmd
+=
' && echo
%
s'
%
basetmp
result
=
self
.
_low_level_exec_command
(
conn
,
cmd
,
None
,
sudoable
=
False
)
return
result
.
split
(
"
\n
"
)[
0
]
.
strip
()
+
'/'
return
utils
.
last_non_blank_line
(
result
)
.
strip
()
+
'/'
# *****************************************************
...
...
lib/ansible/runner/connection/ssh.py
View file @
3cc564c1
...
...
@@ -60,7 +60,7 @@ class SSHConnection(object):
ssh_cmd
=
[
"ssh"
,
"-tt"
,
"-q"
]
+
self
.
common_args
+
[
self
.
host
]
if
self
.
runner
.
sudo
and
sudoable
:
# Rather than detect if sudo wants a password this time, -k makes
# sudo always ask for a password if one is required.
# sudo always ask for a password if one is required.
# Passing a quoted compound command to sudo (or sudo -s)
# directly doesn't work, so we shellquote it with pipes.quote()
# and pass the quoted string to the user's shell. We loop reading
...
...
@@ -98,16 +98,12 @@ class SSHConnection(object):
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
# We can't use p.communicate here because the ControlMaster may have stdout open as well
p
.
stdin
.
close
()
stdout
=
''
while
p
.
poll
()
is
None
:
rfd
,
wfd
,
efd
=
select
.
select
([
p
.
stdout
],
[],
[
p
.
stdout
],
1
)
if
p
.
stdout
in
rfd
:
stdout
+=
os
.
read
(
p
.
stdout
.
fileno
(),
1024
)
# older versions of ssh generate this error which we ignore
stdout
=
stdout
.
replace
(
"tcgetattr: Invalid argument
\n
"
,
""
)
# suppress Ubuntu 10.04/12.04 error on -tt option
stdout
=
stdout
.
replace
(
"tcgetattr: Inappropriate ioctl for device
\n
"
,
""
)
p
.
stdin
.
close
()
# close stdin after we read from stdout (see also issue #848)
if
p
.
returncode
!=
0
and
stdout
.
find
(
'Bad configuration option: ControlPersist'
)
!=
-
1
:
raise
errors
.
AnsibleError
(
'using -c ssh on certain older ssh versions may not support ControlPersist, set ANSIBLE_SSH_ARGS="" before running again'
)
...
...
lib/ansible/utils.py
View file @
3cc564c1
...
...
@@ -117,9 +117,11 @@ def json_loads(data):
return
json
.
loads
(
data
)
def
parse_json
(
data
):
def
parse_json
(
raw_
data
):
''' this version for module return data only '''
data
=
filter_leading_non_json_lines
(
raw_data
)
try
:
return
json
.
loads
(
data
)
except
:
...
...
@@ -307,10 +309,10 @@ def _gitinfo():
branch
=
f
.
readline
()
.
split
(
'/'
)[
-
1
]
.
rstrip
(
"
\n
"
)
branch_path
=
os
.
path
.
join
(
repo_path
,
"refs"
,
"heads"
,
branch
)
with
open
(
branch_path
)
as
f
:
commit
=
f
.
readline
()[:
10
]
commit
=
f
.
readline
()[:
10
]
date
=
time
.
localtime
(
os
.
stat
(
branch_path
)
.
st_mtime
)
offset
=
time
.
timezone
if
(
time
.
daylight
==
0
)
else
time
.
altzone
result
=
"({0} {1}) last updated {2} (GMT {3:+04d})"
.
format
(
branch
,
commit
,
result
=
"({0} {1}) last updated {2} (GMT {3:+04d})"
.
format
(
branch
,
commit
,
time
.
strftime
(
"
%
Y/
%
m/
%
d
%
H:
%
M:
%
S"
,
date
),
offset
/
-
36
)
return
result
...
...
@@ -415,3 +417,29 @@ def do_encrypt(result, encrypt, salt_size=None, salt=None):
return
result
def
last_non_blank_line
(
lines
):
all_lines
=
lines
.
splitlines
()
all_lines
.
reverse
()
for
line
in
all_lines
:
if
(
len
(
line
)
>
0
):
return
line
return
""
# we shouldn't come here (no lines?) but let's pretend nothing happend
# We can't return all lines here because calling code expects only one
# line. And since we don't know which line to return we return an empty
# line.
def
is_valid_json_line
(
line
):
return
line
.
startswith
(
'='
)
or
line
.
startswith
(
'{'
)
or
line
.
startswith
(
'['
)
def
filter_leading_non_json_lines
(
lines
):
''' we need to filter anything which starts not with '{', '[', ', '=' or is an empty line.
But we filter only leading lines since multiline JSON is valid. '''
filtered_lines
=
''
no_more_filtering
=
False
for
line
in
lines
.
splitlines
():
if
(
no_more_filtering
or
is_valid_json_line
(
line
)):
no_more_filtering
=
True
filtered_lines
+=
line
+
'
\n
'
return
filtered_lines
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