From 4627b3efbb11076aec80bf842870a86a8bdb99b0 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Wed, 20 Jan 2016 15:26:45 -0500 Subject: [PATCH] Standardize removal of BECOME-SUCCESS method and use it for async too Fixes #13965 Fixes #13971 --- lib/ansible/plugins/action/__init__.py | 9 +++++++++ lib/ansible/plugins/action/async.py | 4 ++++ lib/ansible/plugins/action/raw.py | 5 +---- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/ansible/plugins/action/__init__.py b/lib/ansible/plugins/action/__init__.py index 5153986484e..c545e8cd6c8 100644 --- a/lib/ansible/plugins/action/__init__.py +++ b/lib/ansible/plugins/action/__init__.py @@ -24,6 +24,7 @@ import json import os import pipes import random +import re import stat import tempfile import time @@ -356,6 +357,14 @@ class ActionBase(with_metaclass(ABCMeta, object)): return data[idx:] + def _strip_success_message(self, data): + ''' + Removes the BECOME-SUCCESS message from the data. + ''' + if data.strip().startswith('BECOME-SUCCESS-'): + data = re.sub(r'^((\r)?\n)?BECOME-SUCCESS.*(\r)?\n', '', data) + return data + def _execute_module(self, module_name=None, module_args=None, tmp=None, task_vars=None, persist_files=False, delete_remote_tmp=True): ''' Transfer and run a module along with its arguments. diff --git a/lib/ansible/plugins/action/async.py b/lib/ansible/plugins/action/async.py index 8a7175aeb86..5e04f37ff12 100644 --- a/lib/ansible/plugins/action/async.py +++ b/lib/ansible/plugins/action/async.py @@ -75,4 +75,8 @@ class ActionModule(ActionBase): result['changed'] = True + # be sure to strip out the BECOME-SUCCESS message, which may + # be there depending on the output of the module + result['stdout'] = self._strip_success_message(result.get('stdout', '')) + return result diff --git a/lib/ansible/plugins/action/raw.py b/lib/ansible/plugins/action/raw.py index d6fa2f35599..c9718db4135 100644 --- a/lib/ansible/plugins/action/raw.py +++ b/lib/ansible/plugins/action/raw.py @@ -19,8 +19,6 @@ __metaclass__ = type from ansible.plugins.action import ActionBase -import re - class ActionModule(ActionBase): TRANSFERS_FILES = False @@ -42,7 +40,6 @@ class ActionModule(ActionBase): # for some modules (script, raw), the sudo success key # may leak into the stdout due to the way the sudo/su # command is constructed, so we filter that out here - if result.get('stdout','').strip().startswith('BECOME-SUCCESS-'): - result['stdout'] = re.sub(r'^((\r)?\n)?BECOME-SUCCESS.*(\r)?\n', '', result['stdout']) + result['stdout'] = self._strip_success_message(result.get('stdout', '')) return result