mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00:00
Starting to add additional unit tests for VariableManager
Required some rewiring in inventory code to make sure we're using the DataLoader class for some data file operations, which makes mocking them much easier. Also identified two corner cases not currently handled by the code, related to inventory variable sources and which one "wins". Also noticed we weren't properly merging variables from multiple group/host_var file locations (inventory directory vs. playbook directory locations) so fixed as well.
This commit is contained in:
@@ -114,12 +114,15 @@ class Host:
|
||||
def get_vars(self):
|
||||
|
||||
results = {}
|
||||
groups = self.get_groups()
|
||||
for group in sorted(groups, key=lambda g: g.depth):
|
||||
results = combine_vars(results, group.get_vars())
|
||||
results = combine_vars(results, self.vars)
|
||||
results['inventory_hostname'] = self.name
|
||||
results['inventory_hostname_short'] = self.name.split('.')[0]
|
||||
results['group_names'] = sorted([ g.name for g in groups if g.name != 'all'])
|
||||
results['group_names'] = sorted([ g.name for g in self.get_groups() if g.name != 'all'])
|
||||
return results
|
||||
|
||||
def get_group_vars(self):
|
||||
results = {}
|
||||
groups = self.get_groups()
|
||||
for group in sorted(groups, key=lambda g: g.depth):
|
||||
results = combine_vars(results, group.get_vars())
|
||||
return results
|
||||
|
||||
Reference in New Issue
Block a user