From 670894e2bd951d8b79adbf1339cf131242fd4eb7 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Tue, 2 Jun 2015 14:16:39 -0500 Subject: [PATCH 1/2] Move building the play_ds into a method, that can be overridden --- lib/ansible/cli/adhoc.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/ansible/cli/adhoc.py b/lib/ansible/cli/adhoc.py index 3607e3ee03d..9bc234507c9 100644 --- a/lib/ansible/cli/adhoc.py +++ b/lib/ansible/cli/adhoc.py @@ -65,6 +65,13 @@ class AdHocCLI(CLI): return True + def _play_ds(self, pattern): + return dict( + name = "Ansible Ad-Hoc", + hosts = pattern, + gather_facts = 'no', + tasks = [ dict(action=dict(module=self.options.module_name, args=parse_kv(self.options.module_args))), ] + ) def run(self): ''' use Runner lib to do SSH things ''' @@ -117,13 +124,7 @@ class AdHocCLI(CLI): # results = runner.run() # create a pseudo-play to execute the specified module via a single task - play_ds = dict( - name = "Ansible Ad-Hoc", - hosts = pattern, - gather_facts = 'no', - tasks = [ dict(action=dict(module=self.options.module_name, args=parse_kv(self.options.module_args))), ] - ) - + play_ds = self._play_ds(pattern) play = Play().load(play_ds, variable_manager=variable_manager, loader=loader) # now create a task queue manager to execute the play From 1d55e193c1041c907793aca91395eddc8a10a74c Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Mon, 15 Jun 2015 13:04:46 -0500 Subject: [PATCH 2/2] Expose the TaskQueueManager to self --- lib/ansible/cli/adhoc.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/ansible/cli/adhoc.py b/lib/ansible/cli/adhoc.py index 9bc234507c9..e940a0224f6 100644 --- a/lib/ansible/cli/adhoc.py +++ b/lib/ansible/cli/adhoc.py @@ -128,9 +128,9 @@ class AdHocCLI(CLI): play = Play().load(play_ds, variable_manager=variable_manager, loader=loader) # now create a task queue manager to execute the play - tqm = None + self._tqm = None try: - tqm = TaskQueueManager( + self._tqm = TaskQueueManager( inventory=inventory, variable_manager=variable_manager, loader=loader, @@ -139,10 +139,10 @@ class AdHocCLI(CLI): passwords=passwords, stdout_callback='minimal', ) - result = tqm.run(play) + result = self._tqm.run(play) finally: - if tqm: - tqm.cleanup() + if self._tqm: + self._tqm.cleanup() return result