Merge branch 'devel' of https://github.com/SleeplessAnnoyedNerd/ansible into devel
This commit is contained in:
commit
3cc564c127
3 changed files with 35 additions and 11 deletions
|
@ -655,7 +655,7 @@ class Runner(object):
|
||||||
|
|
||||||
cmd = " || ".join(md5s)
|
cmd = " || ".join(md5s)
|
||||||
cmd = "%s; %s || (echo \"${rc} %s\")" % (test, cmd, path)
|
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
|
cmd += ' && echo %s' % basetmp
|
||||||
|
|
||||||
result = self._low_level_exec_command(conn, cmd, None, sudoable=False)
|
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() + '/'
|
||||||
|
|
||||||
# *****************************************************
|
# *****************************************************
|
||||||
|
|
||||||
|
|
|
@ -98,16 +98,12 @@ class SSHConnection(object):
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||||
|
|
||||||
# We can't use p.communicate here because the ControlMaster may have stdout open as well
|
# We can't use p.communicate here because the ControlMaster may have stdout open as well
|
||||||
p.stdin.close()
|
|
||||||
stdout = ''
|
stdout = ''
|
||||||
while p.poll() is None:
|
while p.poll() is None:
|
||||||
rfd, wfd, efd = select.select([p.stdout], [], [p.stdout], 1)
|
rfd, wfd, efd = select.select([p.stdout], [], [p.stdout], 1)
|
||||||
if p.stdout in rfd:
|
if p.stdout in rfd:
|
||||||
stdout += os.read(p.stdout.fileno(), 1024)
|
stdout += os.read(p.stdout.fileno(), 1024)
|
||||||
# older versions of ssh generate this error which we ignore
|
p.stdin.close() # close stdin after we read from stdout (see also issue #848)
|
||||||
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","")
|
|
||||||
|
|
||||||
if p.returncode != 0 and stdout.find('Bad configuration option: ControlPersist') != -1:
|
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')
|
raise errors.AnsibleError('using -c ssh on certain older ssh versions may not support ControlPersist, set ANSIBLE_SSH_ARGS="" before running again')
|
||||||
|
|
|
@ -117,9 +117,11 @@ def json_loads(data):
|
||||||
|
|
||||||
return json.loads(data)
|
return json.loads(data)
|
||||||
|
|
||||||
def parse_json(data):
|
def parse_json(raw_data):
|
||||||
''' this version for module return data only '''
|
''' this version for module return data only '''
|
||||||
|
|
||||||
|
data = filter_leading_non_json_lines(raw_data)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return json.loads(data)
|
return json.loads(data)
|
||||||
except:
|
except:
|
||||||
|
@ -415,3 +417,29 @@ def do_encrypt(result, encrypt, salt_size=None, salt=None):
|
||||||
|
|
||||||
return result
|
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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue