From 0c1f62065cc8f72a832b96f89cfb5fc5a9718026 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Mon, 10 Dec 2018 11:40:44 -0500 Subject: [PATCH] make adhoc include_role/task work again! (#49247) * adhoc include_role/task work again! - fix task, pass if set --- changelogs/fragments/fix_adhoc_includes.yml | 2 ++ lib/ansible/cli/adhoc.py | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/fix_adhoc_includes.yml diff --git a/changelogs/fragments/fix_adhoc_includes.yml b/changelogs/fragments/fix_adhoc_includes.yml new file mode 100644 index 0000000000..87139eee38 --- /dev/null +++ b/changelogs/fragments/fix_adhoc_includes.yml @@ -0,0 +1,2 @@ +bugfixes: + - adhoc always added async_val and poll to tasks, but now includes are enforcing non valid parameters, this bypasses the error. diff --git a/lib/ansible/cli/adhoc.py b/lib/ansible/cli/adhoc.py index 0185f56ece..0042556d76 100644 --- a/lib/ansible/cli/adhoc.py +++ b/lib/ansible/cli/adhoc.py @@ -76,13 +76,19 @@ class AdHocCLI(CLI): def _play_ds(self, pattern, async_val, poll): check_raw = self.options.module_name in ('command', 'win_command', 'shell', 'win_shell', 'script', 'raw') + + mytask = {'action': {'module': self.options.module_name, 'args': parse_kv(self.options.module_args, check_raw=check_raw)}} + + # avoid adding to tasks that don't support it, unless set, then give user an error + if self.options.module_name not in ('include_role', 'include_tasks') or any(async_val, poll): + mytask['async_val'] = async_val + mytask['poll'] = poll + 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, check_raw=check_raw)), async_val=async_val, - poll=poll)] - ) + tasks=[mytask]) def run(self): ''' create and execute the single task playbook '''