Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow AdHocCLI to be more flexible for overriding #11271

Merged
merged 2 commits into from Jun 15, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 13 additions & 12 deletions lib/ansible/cli/adhoc.py
Expand Up @@ -65,6 +65,13 @@ def parse(self):

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 '''
Expand Down Expand Up @@ -117,19 +124,13 @@ def run(self):
# 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
tqm = None
self._tqm = None
try:
tqm = TaskQueueManager(
self._tqm = TaskQueueManager(
inventory=inventory,
variable_manager=variable_manager,
loader=loader,
Expand All @@ -138,10 +139,10 @@ def run(self):
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

Expand Down