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>
This commit is contained in:
parent
0e09800a9a
commit
48d4d6ec69
4 changed files with 14 additions and 4 deletions
2
changelogs/fragments/hash_behaviour_inventory.yml
Normal file
2
changelogs/fragments/hash_behaviour_inventory.yml
Normal file
|
@ -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
|
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
|
Command Line
|
||||||
|
|
|
@ -22,8 +22,9 @@ from itertools import chain
|
||||||
from ansible import constants as C
|
from ansible import constants as C
|
||||||
from ansible.errors import AnsibleError
|
from ansible.errors import AnsibleError
|
||||||
from ansible.module_utils._text import to_native, to_text
|
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.display import Display
|
||||||
|
from ansible.utils.vars import combine_vars
|
||||||
|
|
||||||
display = Display()
|
display = Display()
|
||||||
|
|
||||||
|
@ -245,7 +246,10 @@ class Group:
|
||||||
if key == 'ansible_group_priority':
|
if key == 'ansible_group_priority':
|
||||||
self.set_priority(int(value))
|
self.set_priority(int(value))
|
||||||
else:
|
else:
|
||||||
self.vars[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 clear_hosts_cache(self):
|
def clear_hosts_cache(self):
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ from __future__ import (absolute_import, division, print_function)
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
from ansible.inventory.group import Group
|
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
|
from ansible.utils.vars import combine_vars, get_unique_id
|
||||||
|
|
||||||
__all__ = ['Host']
|
__all__ = ['Host']
|
||||||
|
@ -137,7 +138,10 @@ class Host:
|
||||||
self.remove_group(oldg)
|
self.remove_group(oldg)
|
||||||
|
|
||||||
def set_variable(self, key, value):
|
def set_variable(self, key, value):
|
||||||
self.vars[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):
|
def get_groups(self):
|
||||||
return self.groups
|
return self.groups
|
||||||
|
|
Loading…
Reference in a new issue