From 3e1a774ba5108c1bebf98af96ea57bb695a65157 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Tue, 1 Sep 2015 14:11:23 -0400 Subject: [PATCH] Don't use iteritems() in templar to avoid (hostvars) dict size change errors --- lib/ansible/template/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/ansible/template/__init__.py b/lib/ansible/template/__init__.py index 77ea365b09c..624a7c87a6d 100644 --- a/lib/ansible/template/__init__.py +++ b/lib/ansible/template/__init__.py @@ -251,8 +251,10 @@ class Templar: return [self.template(v, convert_bare=convert_bare, preserve_trailing_newlines=preserve_trailing_newlines, fail_on_undefined=fail_on_undefined, overrides=overrides) for v in variable] elif isinstance(variable, dict): d = {} - for (k, v) in variable.iteritems(): - d[k] = self.template(v, convert_bare=convert_bare, preserve_trailing_newlines=preserve_trailing_newlines, fail_on_undefined=fail_on_undefined, overrides=overrides) + # we don't use iteritems() here to avoid problems if the underlying dict + # changes sizes due to the templating, which can happen with hostvars + for k in variable.keys(): + d[k] = self.template(variable[k], convert_bare=convert_bare, preserve_trailing_newlines=preserve_trailing_newlines, fail_on_undefined=fail_on_undefined, overrides=overrides) return d else: return variable