Created
October 1, 2014 21:30
-
-
Save abadger/e00f644881c3e80b3cf3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/ansible/modules/core b/lib/ansible/modules/core | |
--- a/lib/ansible/modules/core | |
+++ b/lib/ansible/modules/core | |
@@ -1 +1 @@ | |
-Subproject commit db5668b84c3a19498b843d0bfe34574aef40c193 | |
+Subproject commit db5668b84c3a19498b843d0bfe34574aef40c193-dirty | |
diff --git a/lib/ansible/modules/extras b/lib/ansible/modules/extras | |
--- a/lib/ansible/modules/extras | |
+++ b/lib/ansible/modules/extras | |
@@ -1 +1 @@ | |
-Subproject commit 110250d344be156387d08ea837f4bcb2c42034b4 | |
+Subproject commit 110250d344be156387d08ea837f4bcb2c42034b4-dirty | |
diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py | |
index 19c90ba..bf79d06 100644 | |
--- a/lib/ansible/runner/__init__.py | |
+++ b/lib/ansible/runner/__init__.py | |
@@ -682,16 +682,6 @@ 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', 'zypper' ]: | |
- # hack for apt, yum, and pkgng so that with_items maps back into a single module call | |
- use_these_items = [] | |
- for x in items: | |
- inject['item'] = x | |
- if not self.conditional or utils.check_conditional(self.conditional, self.basedir, inject, fail_on_undefined=self.error_on_undefined_vars): | |
- use_these_items.append(x) | |
- inject['item'] = ",".join(use_these_items) | |
- items = None | |
- | |
def _safe_template_complex_args(args, inject): | |
# Ensure the complex args here are a dictionary, but | |
# first template them if they contain a variable | |
@@ -736,14 +726,43 @@ class Runner(object): | |
all_comm_ok = True | |
all_changed = False | |
all_failed = False | |
- results = [] | |
+ templated_args = [] | |
for x in items: | |
# use a fresh inject for each item | |
this_inject = inject.copy() | |
this_inject['item'] = x | |
- complex_args = _safe_template_complex_args(self.complex_args, this_inject) | |
+ templated_args.append(_safe_template_complex_args(self.complex_args, this_inject)) | |
+ | |
+ # hack for apt, yum, and pkgng so that with_items maps back into a single module call | |
+ # This is significantly faster but we have to be careful not to | |
+ # overoptimize | |
+ if self.module_name in ('apt', 'yum', 'pkgng', 'zypper'): | |
+ # Verify: Do we have to deal with aliases for yum, apt, pkgng, | |
+ # and zypper's name/pkg parameter? | |
+ # | |
+ # Note: have to specify that the parameters are type list in | |
+ # their modules. yum and pkgng need changing | |
+ arg_being_merged = dict(yum='name', apt='package', pkgng='name', zypper='name') | |
+ merged_args = dict() | |
+ abm = arg_being_merged[self.module_name] | |
+ # paranoia: when in separate package manager calls, makes sure | |
+ # that the order of the calls matches the order in which the | |
+ # packages were specified. | |
+ serial = 0 | |
+ for args in templated_args: | |
+ temp_args = args.copy() | |
+ temp_args[abm] = None | |
+ if temp_args in merged_args: | |
+ merged_args[temp_args] = (merged_args[temp_args][0], | |
+ ','.join(merged_args[temp_args][1], args[abm])) | |
+ else: | |
+ merged_args[temp_args] = (serial, args) | |
+ serial += 1 | |
+ templated_args = [a[1] for a in sorted(merged_args.itervalues())] | |
+ results = [] | |
+ for complex_args in templated_args: | |
result = self._executor_internal_inner( | |
host, | |
self.module_name, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment