Michael DeHaan
unread,Aug 11, 2012, 8:53:39 AM8/11/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ansible...@googlegroups.com
Before we consider this, what kind of SSH daemon or setting is this that sends MOTD every single time?
I have some ideas, but it seems so non-standard that it's almost not worth including the code hack. But I could be persuaded...
On Saturday, August 11, 2012 at 6:32 AM, Dietmar Schinnerl wrote:
> Hi,
>
> unfortunately I have some hosts[1] which always send MOTD back to the client which -- of course -- breaks parsing of [Baby] JSON (and also the parsing of the temp path during "setup" which is empty because of that). Sure, one solution would be to remove MOTD or install "better" SSH daemon. (But both solutions I don't like.) But on the other hand I wonder if it would make sense to make ansible's parsing of stdout/-err more resilient to "garbage". E.g. at least ignore lines which start with '#'. (Or just use the last line of the stdout/-err for parsing of [Baby] JSON result?)
>
> A hackish solution for the case "line starts with '#'" you find at the end of this post (which works for me, YMMV).
>
> Anyways, maybe the code has some use for someone if it is not feasible to include this into ansible core (controllable by flag per host/task?). (I'm pretty sure there are some odd implications I don't see. Although I like the idea of ignoring such lines. But I'm a bit biased on that. :) )
>
> Thanks,
> Dietmar
>
> [1] Dropbear 0.48.1-1 does that.
>
> diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py
> index 6a43a59..cb2c586 100644
> --- a/lib/ansible/runner/__init__.py
> +++ b/lib/ansible/runner/__init__.py
> @@ -673,7 +673,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.filter_comment_lines(result).split("\n")[0].strip() + '/'
>
> # *****************************************************
>
> diff --git a/lib/ansible/utils.py b/lib/ansible/utils.py
> index b8db010..2851ddb 100644
> --- a/lib/ansible/utils.py
> +++ b/lib/ansible/utils.py
> @@ -106,9 +106,11 @@ def json_loads(data):
>
> return json.loads(data)
>
> +
> def parse_json(data):
> ''' this version for module return data only '''
>
> + data = filter_comment_lines(data)
> try:
> return json.loads(data)
> except:
> @@ -353,4 +355,10 @@ def base_parser(constants=C, usage="", output_opts=False, runas_opts=False, asyn
> return parser
>
>
> +def filter_comment_lines(data):
> + filtered_data = ''
> + for line in data.splitlines():
> + if (not line.startswith('#')):
> + filtered_data += line + '\n'
> + return filtered_data