diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index 5eb3f5e46ec..831bd2cdc56 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -34,6 +34,7 @@ from ansible import errors from ansible import module_common import poller import connection +from return_data import ReturnData from ansible.callbacks import DefaultRunnerCallbacks, vv HAS_ATFORK=True @@ -63,48 +64,6 @@ def _executor_hook(job_queue, result_queue): except: traceback.print_exc() -################################################ - -class ReturnData(object): - ''' internal return class for execute methods, not part of API signature ''' - - __slots__ = [ 'result', 'comm_ok', 'host' ] - - def __init__(self, conn=None, host=None, result=None, comm_ok=True): - - # which host is this ReturnData about? - if conn is not None: - delegate_for = getattr(conn, '_delegate_for', None) - if delegate_for: - self.host = delegate_for - else: - self.host = conn.host - else: - self.host = host - - self.result = result - self.comm_ok = comm_ok - - if type(self.result) in [ str, unicode ]: - self.result = utils.parse_json(self.result) - - if self.host is None: - raise Exception("host not set") - if type(self.result) != dict: - raise Exception("dictionary result expected") - - def communicated_ok(self): - return self.comm_ok - - def is_successful(self): - return self.comm_ok and ('failed' not in self.result) and (self.result.get('rc',0) == 0) - - def daisychain(self, module_name): - ''' request a module call follow this one ''' - if self.is_successful(): - self.result['daisychain'] = module_name - return self - class Runner(object): ''' core API interface to ansible ''' diff --git a/lib/ansible/runner/return_data.py b/lib/ansible/runner/return_data.py new file mode 100644 index 00000000000..0dcdb4aeb8a --- /dev/null +++ b/lib/ansible/runner/return_data.py @@ -0,0 +1,59 @@ +# (c) 2012, Michael DeHaan +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +from ansible import utils + +class ReturnData(object): + ''' internal return class for runner execute methods, not part of public API signature ''' + + __slots__ = [ 'result', 'comm_ok', 'host' ] + + def __init__(self, conn=None, host=None, result=None, comm_ok=True): + + # which host is this ReturnData about? + if conn is not None: + delegate_for = getattr(conn, '_delegate_for', None) + if delegate_for: + self.host = delegate_for + else: + self.host = conn.host + else: + self.host = host + + self.result = result + self.comm_ok = comm_ok + + if type(self.result) in [ str, unicode ]: + self.result = utils.parse_json(self.result) + + if self.host is None: + raise Exception("host not set") + if type(self.result) != dict: + raise Exception("dictionary result expected") + + def communicated_ok(self): + return self.comm_ok + + def is_successful(self): + return self.comm_ok and ('failed' not in self.result) and (self.result.get('rc',0) == 0) + + def daisychain(self, module_name): + ''' request a module call follow this one ''' + if self.is_successful(): + self.result['daisychain'] = module_name + return self +