allow more 'backwards compatible' vars_plugins (#25451)
* allow more 'backwards compatible' vars_plugins * better version relying on exceptionspull/4420/head
parent
89caef8fb6
commit
a2cff554ee
|
@ -229,6 +229,24 @@ class VariableManager:
|
||||||
all_group = self._inventory.groups.get('all')
|
all_group = self._inventory.groups.get('all')
|
||||||
host_groups = sort_groups([g for g in host.get_groups() if g.name not in ['all']])
|
host_groups = sort_groups([g for g in host.get_groups() if g.name not in ['all']])
|
||||||
|
|
||||||
|
def _get_plugin_vars(plugin, loader, path, entities):
|
||||||
|
data = {}
|
||||||
|
try:
|
||||||
|
data = plugin.get_vars(self._loader, path, entities)
|
||||||
|
except AttributeError:
|
||||||
|
try:
|
||||||
|
for entity in entities:
|
||||||
|
if isinstance(entity, Host):
|
||||||
|
data.update(plugin.get_host_vars(entity.name))
|
||||||
|
else:
|
||||||
|
data.update(plugin.get_group_vars(entity.name))
|
||||||
|
except AttributeError:
|
||||||
|
if hasattr(plugin, 'run'):
|
||||||
|
raise AnsibleError("Cannot use v1 type vars plugin %s from %s" % (plugin._load_name, plugin._original_path))
|
||||||
|
else:
|
||||||
|
raise AnsibleError("Invalid vars plugin %s from %s" % (plugin._load_name, plugin._original_path))
|
||||||
|
return data
|
||||||
|
|
||||||
# internal fuctions that actually do the work
|
# internal fuctions that actually do the work
|
||||||
def _plugins_inventory(entities):
|
def _plugins_inventory(entities):
|
||||||
''' merges all entities by inventory source '''
|
''' merges all entities by inventory source '''
|
||||||
|
@ -240,15 +258,14 @@ class VariableManager:
|
||||||
inventory_dir = os.path.dirname(inventory_dir)
|
inventory_dir = os.path.dirname(inventory_dir)
|
||||||
|
|
||||||
for plugin in vars_loader.all():
|
for plugin in vars_loader.all():
|
||||||
data = combine_vars(data, plugin.get_vars(self._loader, inventory_dir, entities))
|
data = combine_vars(data, _get_plugin_vars(plugin, self._loader, inventory_dir, entities))
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def _plugins_play(entities):
|
def _plugins_play(entities):
|
||||||
''' merges all entities adjacent to play '''
|
''' merges all entities adjacent to play '''
|
||||||
data = {}
|
data = {}
|
||||||
for plugin in vars_loader.all():
|
for plugin in vars_loader.all():
|
||||||
data = combine_vars(data, plugin.get_vars(self._loader, basedir, entities))
|
data = combine_vars(data, _get_plugin_vars(plugin, self._loader, basedir, entities))
|
||||||
return data
|
return data
|
||||||
|
|
||||||
# configurable functions that are sortable via config
|
# configurable functions that are sortable via config
|
||||||
|
|
Loading…
Reference in New Issue