From 4942a06bc2b229b10df19491fbe64e166f53e6ab Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Sat, 15 Jun 2013 16:28:43 -0400 Subject: [PATCH] now modules can implement with_items list globbing w/o updating hardcoded lists in ansible code, just add WITH_ITEMS_USES_LIST in a comment anywhere, and of course, support recieving params as list. Signed-off-by: Brian Coca --- lib/ansible/runner/__init__.py | 8 ++++++-- library/packaging/apt | 1 + library/packaging/pkgng | 1 + library/packaging/yum | 1 + 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index 9ee9e54a12..b27f475a59 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -163,6 +163,7 @@ class Runner(object): self.is_playbook = is_playbook self.environment = environment self.complex_args = complex_args + self.module_with_list = False self.callbacks.runner = self @@ -405,8 +406,8 @@ class Runner(object): if type(items) != list: raise errors.AnsibleError("lookup plugins have to return a list: %r" % items) - if len(items) and utils.is_list_of_strings(items) and self.module_name in [ 'apt', 'yum', 'pkgng' ]: - # hack for apt, yum, and pkgng so that with_items maps back into a single module call + if len(items) and utils.is_list_of_strings(items) and self.module_with_list: + # with_items maps back into a single module call, making modules that support this more efficient inject['item'] = ",".join(items) items = None @@ -711,6 +712,9 @@ class Runner(object): if 'WANT_JSON' in module_data: module_style = 'non_native_want_json' + if 'WITH_ITEMS_USES_LIST' in module_data: + self.module_with_list = True + complex_args_json = utils.jsonify(complex_args) # We force conversion of module_args to str because module_common calls shlex.split, # a standard library function that incorrectly handles Unicode input before Python 2.7.3. diff --git a/library/packaging/apt b/library/packaging/apt index 04d7eb82b9..1a6ce392cf 100644 --- a/library/packaging/apt +++ b/library/packaging/apt @@ -1,5 +1,6 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +# WITH_ITEMS_USES_LIST # (c) 2012, Flowroute LLC # Written by Matthew Williams diff --git a/library/packaging/pkgng b/library/packaging/pkgng index ec0469bdc3..ce59e28e53 100644 --- a/library/packaging/pkgng +++ b/library/packaging/pkgng @@ -1,5 +1,6 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +# WITH_ITEMS_USES_LIST # (c) 2013, bleader # Written by bleader diff --git a/library/packaging/yum b/library/packaging/yum index 921b13db1a..698c8bf6f3 100644 --- a/library/packaging/yum +++ b/library/packaging/yum @@ -1,5 +1,6 @@ #!/usr/bin/python -tt # -*- coding: utf-8 -*- +# WITH_ITEMS_USES_LIST # (c) 2012, Red Hat, Inc # Written by Seth Vidal