mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
make groups magic var dependant on inventory (#28677)
* make groups magic var dependant on inventory it was overtly restricted by 'host' minor fixes to test_var_manager.py, need to test other values also * pepe hates extra blank line
This commit is contained in:
parent
de6ba4daff
commit
f9b3f4f934
2 changed files with 6 additions and 11 deletions
|
@ -457,10 +457,6 @@ class VariableManager:
|
|||
variables['playbook_dir'] = os.path.abspath(self._loader.get_basedir())
|
||||
variables['ansible_playbook_python'] = sys.executable
|
||||
|
||||
if host:
|
||||
# host already provides some magic vars via host.get_vars()
|
||||
if self._inventory:
|
||||
variables['groups'] = self._inventory.get_groups_dict()
|
||||
if play:
|
||||
variables['role_names'] = [r._role_name for r in play.roles]
|
||||
|
||||
|
@ -471,6 +467,7 @@ class VariableManager:
|
|||
variables['role_uuid'] = text_type(task._role._uuid)
|
||||
|
||||
if self._inventory is not None:
|
||||
variables['groups'] = self._inventory.get_groups_dict()
|
||||
if play:
|
||||
templar = Templar(loader=self._loader)
|
||||
if templar.is_template(play.hosts):
|
||||
|
|
|
@ -50,14 +50,12 @@ class TestVariableManager(unittest.TestCase):
|
|||
|
||||
mock_inventory = MagicMock()
|
||||
v = VariableManager(loader=fake_loader, inventory=mock_inventory)
|
||||
vars = v.get_vars(use_cache=False)
|
||||
variables = v.get_vars(use_cache=False)
|
||||
|
||||
# FIXME: not sure why we remove all and only test playbook_dir
|
||||
for remove in ['omit', 'vars', 'ansible_version', 'ansible_check_mode', 'ansible_playbook_python']:
|
||||
if remove in vars:
|
||||
del vars[remove]
|
||||
|
||||
self.assertEqual(vars, dict(playbook_dir=os.path.abspath('.')))
|
||||
# Check var manager expected values, never check: ['omit', 'vars']
|
||||
# FIXME: add the following ['ansible_version', 'ansible_playbook_python', 'groups']
|
||||
for varname, value in (('playbook_dir', os.path.abspath('.')), ):
|
||||
self.assertEqual(variables[varname], value)
|
||||
|
||||
def test_variable_manager_extra_vars(self):
|
||||
fake_loader = DictDataLoader({})
|
||||
|
|
Loading…
Reference in a new issue