Exemple #1
0
    def parse(self, inventory, loader, path, cache=True):
        config_data = loader.load_from_file(path, cache=False)

        try:
            plugin_name = config_data.get('plugin', None)
        except AttributeError:
            plugin_name = None

        if not plugin_name:
            raise AnsibleParserError("no root 'plugin' key found, '{0}' is not a valid YAML inventory plugin config file".format(path))

        plugin = inventory_loader.get(plugin_name)

        if not plugin:
            raise AnsibleParserError("inventory config '{0}' specifies unknown plugin '{1}'".format(path, plugin_name))

        if not plugin.verify_file(path):
            raise AnsibleParserError("inventory source '{0}' could not be verified by inventory plugin '{1}'".format(path, plugin_name))

        self.display.v("Using inventory plugin '{0}' to process inventory source '{1}'".format(plugin._load_name, path))
        plugin.parse(inventory, loader, path, cache=cache)
        try:
            plugin.update_cache_if_changed()
        except AttributeError:
            pass
 def _fetch_inventory_plugins(self):
     plugins = super()._fetch_inventory_plugins()
     inventory_loader.add_directory(
         'playbooks/roles/install-ansible/files/inventory_plugins')
     for plugin_name in ['yamlgroup']:
         plugin = inventory_loader.get(plugin_name)
         if plugin:
             plugins.append(plugin)
     return plugins
Exemple #3
0
    def _setup_inventory_plugins(self):
        ''' sets up loaded inventory plugins for usage '''

        display.vvvv('setting up inventory plugins')

        for name in C.INVENTORY_ENABLED:
            plugin = inventory_loader.get(name)
            if plugin:
                self._inventory_plugins.append(plugin)
            else:
                display.warning('Failed to load inventory plugin, skipping %s' % name)

        if not self._inventory_plugins:
            raise AnsibleError("No inventory plugins available to generate inventory, make sure you have at least one whitelisted.")
Exemple #4
0
    def parse(self, inventory, loader, path, cache=True):
        config_data = loader.load_from_file(path, cache=False)

        plugin_name = config_data.get('plugin')

        if not plugin_name:
            raise AnsibleParserError("no root 'plugin' key found, '{0}' is not a valid YAML inventory plugin config file".format(path))

        plugin = inventory_loader.get(plugin_name)

        if not plugin:
            raise AnsibleParserError("inventory config '{0}' specifies unknown plugin '{1}'".format(path, plugin_name))

        if not plugin.verify_file(path):
            raise AnsibleParserError("inventory config '{0}' could not be verified by plugin '{1}'".format(path, plugin_name))

        plugin.parse(inventory, loader, path, cache=cache)
Exemple #5
0
    def parse(self, inventory, loader, path, cache=True):
        config_data = loader.load_from_file(path, cache=False)

        plugin_name = config_data.get('plugin')

        if not plugin_name:
            raise AnsibleParserError("no root 'plugin' key found, '{0}' is not a valid YAML inventory plugin config file".format(path))

        plugin = inventory_loader.get(plugin_name)

        if not plugin:
            raise AnsibleParserError("inventory config '{0}' specifies unknown plugin '{1}'".format(path, plugin_name))

        if not plugin.verify_file(path):
            raise AnsibleParserError("inventory config '{0}' could not be verified by plugin '{1}'".format(path, plugin_name))

        plugin.parse(inventory, loader, path, cache=cache)
        if getattr(plugin, '_cache', None):
            plugin.update_cache_if_changed()
Exemple #6
0
    def parse(self, inventory, loader, path, cache=True):
        data = loader.load_from_file(path)

        plugin = inventory_loader.get(data["next"])
        next_path = data["path"]
        if not next_path.startswith("/"):
            next_path = os.path.abspath(
                os.path.join(os.path.dirname(path), next_path))
        assert not os.path.samefile(path, next_path)
        try:
            plugin.parse(inventory, loader, next_path, cache=cache)
        except:
            logging.error("alias inner plugin %s parse error" % next_path,
                          exc_info=True)
            raise

        try:
            plugin.update_cache_if_changed()
        except AttributeError:
            pass