Stop ignoring merge hash behaviour in inventory (#58460)

* stop ignoring merge hash behaviour in inventory

fixes #58120

* added porting note

Co-Authored-By: Alicia Cozine <879121+acozine@users.noreply.github.com>
pull/59193/head
Brian Coca 5 years ago committed by GitHub
parent 0e09800a9a
commit 48d4d6ec69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- Inventory sources now respect setting ``hash_behaviour``. Previously each new inventory source would overwrite existing vars, even when ``hash_behavior`` was set to ``merge``.

@ -19,7 +19,7 @@ This document is part of a collection on porting. The complete list of porting g
Playbook
========
No notable changes
* ``hash_behaviour`` now affects inventory sources. If you have it set to ``merge``, the data you get from inventory might change and you will have to update playbooks accordingly. If you're using the default setting (``overwrite``), you will see no changes. Inventory was ignoring this setting.
Command Line

@ -22,8 +22,9 @@ from itertools import chain
from ansible import constants as C
from ansible.errors import AnsibleError
from ansible.module_utils._text import to_native, to_text
from ansible.module_utils.common._collections_compat import Mapping, MutableMapping
from ansible.utils.display import Display
from ansible.utils.vars import combine_vars
display = Display()
@ -244,6 +245,9 @@ class Group:
if key == 'ansible_group_priority':
self.set_priority(int(value))
else:
if key in self.vars and isinstance(self.vars[key], MutableMapping) and isinstance(value, Mapping):
self.vars[key] = combine_vars(self.vars[key], value)
else:
self.vars[key] = value

@ -20,6 +20,7 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible.inventory.group import Group
from ansible.module_utils.common._collections_compat import Mapping, MutableMapping
from ansible.utils.vars import combine_vars, get_unique_id
__all__ = ['Host']
@ -137,6 +138,9 @@ class Host:
self.remove_group(oldg)
def set_variable(self, key, value):
if key in self.vars and isinstance(self.vars[key], MutableMapping) and isinstance(value, Mapping):
self.vars[key] = combine_vars(self.vars[key], value)
else:
self.vars[key] = value
def get_groups(self):

Loading…
Cancel
Save