Create a plugin loader system

This commit is contained in:
Daniel Hokka Zakrisson 2012-11-02 00:41:50 +01:00
commit e05e514861
9 changed files with 118 additions and 85 deletions

View file

@ -29,20 +29,13 @@ from ansible.inventory.host import Host
from ansible import errors
from ansible import utils
# FIXME, adapt.
dirname = os.path.dirname(__file__)
vars_plugin_list = utils.import_plugins(os.path.join(dirname, 'vars_plugins'))
for i in reversed(C.DEFAULT_VARS_PLUGIN_PATH.split(os.pathsep)):
vars_plugin_list.update(utils.import_plugins(i))
class Inventory(object):
"""
Host inventory for ansible.
"""
__slots__ = [ 'host_list', 'groups', '_restriction', '_also_restriction', '_subset', '_is_script',
'parser', '_vars_per_host', '_vars_per_group', '_hosts_cache', '_groups_list',
'_vars_plugins' ]
'parser', '_vars_per_host', '_vars_per_group', '_hosts_cache', '_groups_list']
def __init__(self, host_list=C.DEFAULT_HOST_LIST):
@ -74,6 +67,9 @@ class Inventory(object):
host_list = host_list.split(",")
host_list = [ h for h in host_list if h and h.strip() ]
else:
utils.plugins.push_basedir(self.basedir())
if type(host_list) == list:
all = Group('all')
self.groups = [ all ]
@ -95,8 +91,6 @@ class Inventory(object):
else:
raise errors.AnsibleError("YAML inventory support is deprecated in 0.6 and removed in 0.7, see the migration script in examples/scripts in the git checkout")
self._vars_plugins = [ i.VarsModule(self) for i in vars_plugin_list.values() ]
def _match(self, str, pattern_str):
return fnmatch.fnmatch(str, pattern_str)
@ -280,8 +274,7 @@ class Inventory(object):
raise errors.AnsibleError("host not found: %s" % hostname)
vars = {}
for ip in self._vars_plugins:
updated = ip.run(host)
for updated in map(lambda x: x.run(host), utils.plugins.vars_loader.all(self)):
if updated is not None:
vars.update(updated)