From ed14312ad6ba58074dfcb4290f6e15b83b0c9ac9 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Wed, 1 Aug 2012 19:42:31 -0400 Subject: [PATCH] reinstate invalid argument checks where possible, daisy chainee/chained modules turn it off --- lib/ansible/module_common.py | 9 ++++++--- library/copy | 2 ++ library/file | 10 ++-------- library/get_url | 2 ++ 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/ansible/module_common.py b/lib/ansible/module_common.py index 3163da83c85..ce0a2c55b89 100644 --- a/lib/ansible/module_common.py +++ b/lib/ansible/module_common.py @@ -54,7 +54,7 @@ except ImportError: class AnsibleModule(object): - def __init__(self, argument_spec, bypass_checks=False, no_log=False): + def __init__(self, argument_spec, bypass_checks=False, no_log=False, check_invalid_arguments=True): ''' common code for quickly building an ansible module in Python (although you can write modules in anything that can return JSON) @@ -66,8 +66,11 @@ class AnsibleModule(object): self._legal_inputs = [] self._handle_aliases() - # temporarily disabled - # self._check_invalid_arguments() + + # this may be disabled where modules are going to daisy chain into others + if check_invalid_arguments: + self._check_invalid_arguments() + self._set_defaults(pre=True) if not bypass_checks: diff --git a/library/copy b/library/copy index 66b5921d719..7284a12abf0 100755 --- a/library/copy +++ b/library/copy @@ -23,6 +23,8 @@ import shutil def main(): module = AnsibleModule( + # not checking because of daisy chain to file module + check_invalid_arguments = False, argument_spec = dict( src=dict(required=True), dest=dict(required=True) diff --git a/library/file b/library/file index e9089c569d1..41b8a1d59de 100755 --- a/library/file +++ b/library/file @@ -212,7 +212,8 @@ def rmtree_error(func, path, exc_info): def main(): global module - module = AnsibleFileModule( + module = AnsibleModule( + check_invalid_arguments = False, argument_spec = dict( state = dict(choices=['file','directory','link','absent'], default='file'), path = dict(aliases=['dest', 'name'], required=True), @@ -348,12 +349,5 @@ def main(): # this is magic, see lib/ansible/module_common.py #<> - -class AnsibleFileModule(AnsibleModule): - - def _check_invalid_arguments(self): - # needed to support daisy chaining - pass - main() diff --git a/library/get_url b/library/get_url index 5f166629c93..057a8c662b6 100755 --- a/library/get_url +++ b/library/get_url @@ -128,6 +128,8 @@ def main(): module.fail_json(msg="urlparse is not installed") module = AnsibleModule( + # not checking because of daisy chain to file module + check_invalid_arguments = False, argument_spec = dict( url = dict(required=True), dest = dict(required=True),