Fix logic that prevents multiple action, local_action, and modules to be specified.

pull/7815/head
Toshio Kuratomi 10 years ago
parent 6c94d85690
commit c1b290a311

@ -198,6 +198,12 @@ class ModuleArgsParser:
delegate_to = None delegate_to = None
args = dict() args = dict()
#
# We can have one of action, local_action, or module specified
#
# action
if 'action' in ds: if 'action' in ds:
# an old school 'action' statement # an old school 'action' statement
@ -205,7 +211,8 @@ class ModuleArgsParser:
delegate_to = None delegate_to = None
action, args = self._normalize_parameters(thing) action, args = self._normalize_parameters(thing)
elif 'local_action' in ds: # local_action
if 'local_action' in ds:
# local_action is similar but also implies a delegate_to # local_action is similar but also implies a delegate_to
if action is not None: if action is not None:
@ -214,11 +221,7 @@ class ModuleArgsParser:
delegate_to = 'localhost' delegate_to = 'localhost'
action, args = self._normalize_parameters(thing) action, args = self._normalize_parameters(thing)
else:
# module: <stuff> is the more new-style invocation # module: <stuff> is the more new-style invocation
if action is not None:
raise AnsibleParserError("conflicting action statements", obj=self._task)
# walk the input dictionary to see we recognize a module name # walk the input dictionary to see we recognize a module name
for (item, value) in iteritems(ds): for (item, value) in iteritems(ds):

@ -20,6 +20,7 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type __metaclass__ = type
from ansible.parsing.mod_args import ModuleArgsParser from ansible.parsing.mod_args import ModuleArgsParser
from ansible.errors import AnsibleParserError
from ansible.compat.tests import unittest from ansible.compat.tests import unittest
@ -106,3 +107,9 @@ class TestModArgsDwim(unittest.TestCase):
self.assertEqual(mod, 'copy') self.assertEqual(mod, 'copy')
self.assertEqual(args, dict(src='a', dest='b')) self.assertEqual(args, dict(src='a', dest='b'))
self.assertIs(to, 'localhost') self.assertIs(to, 'localhost')
def test_multiple_actions(self):
self.assertRaises(AnsibleParserError, self.m.parse, dict(action='shell echo hi', local_action='shell echo hi'))
self.assertRaises(AnsibleParserError, self.m.parse, dict(action='shell echo hi', shell='echo hi'))
self.assertRaises(AnsibleParserError, self.m.parse, dict(local_action='shell echo hi', shell='echo hi'))
self.assertRaises(AnsibleParserError, self.m.parse, dict(ping='data=hi', shell='echo hi'))

Loading…
Cancel
Save