From 13432bb18d9e360692b3799a9490161ad49f4dd0 Mon Sep 17 00:00:00 2001 From: Tim Miller Date: Mon, 20 Jan 2014 15:27:37 -0800 Subject: [PATCH] Make vars plugins honor `hash_behaviour` setting. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When applying precedence ordering of different classes of vars (hostvars, groupvars, role-defaults, etc.), the hash_behaviour setting controls whether duplicate hash keys are replaced in entirety, or merged together. The wording of the documentation suggests that this setting applies to all levels of the precedence ordering, when it currently does not: > Ansible by default will override variables in specific precedence orders, > as described in Variables. When a variable of higher precedence wins, > it will replace the other value. ... Some users prefer that variables that > are hashes (aka ‘dictionaries’ in Python terms) are merged together. This > setting is called ‘merge’. This change causes the hash_behavior setting to extend to vars plugins. --- lib/ansible/inventory/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ansible/inventory/__init__.py b/lib/ansible/inventory/__init__.py index e7979011cdd..337a0377c98 100644 --- a/lib/ansible/inventory/__init__.py +++ b/lib/ansible/inventory/__init__.py @@ -341,12 +341,12 @@ class Inventory(object): raise errors.AnsibleError("host not found: %s" % hostname) vars = {} - vars_results = [ plugin.run(host) for plugin in self._vars_plugins ] + vars_results = [ plugin.run(host) for plugin in self._vars_plugins ] for updated in vars_results: if updated is not None: - vars.update(updated) + vars = utils.combine_vars(vars, updated) - vars.update(host.get_variables()) + vars = utils.combine_vars(vars, host.get_variables()) if self.parser is not None: vars = utils.combine_vars(vars, self.parser.get_host_variables(host)) return vars