def set_options_from_plugin(self, plugin): # generic derived from connection plugin, temporary for backwards compat, in the end we should not set play_context properties # get options for plugins options = C.config.get_configuration_definitions(get_plugin_class(plugin), plugin._load_name) for option in options: if option: flag = options[option].get('name') if flag: setattr(self, flag, self.connection.get_option(flag))
def _load_config_defs(self, name, path): ''' Reads plugin docs to find configuration setting definitions, to push to config manager for later use ''' # plugins w/o class name don't support config if self.class_name and self.class_name in ('Connection'): # FIXME: expand from just connection type_name = get_plugin_class(self) dstring = read_docstring(path, verbose=False, ignore_errors=False) if dstring.get('doc', False): if 'options' in dstring['doc'] and isinstance(dstring['doc']['options'], dict): C.config.initialize_plugin_configuration_definitions(type_name, name, dstring['doc']['options']) display.debug('Loaded config def from plugin (%s/%s)' % (type_name, name))
def set_options(self, task_keys=None, var_options=None, direct=None): ''' This is different than the normal plugin method as callbacks get called early and really don't accept keywords. Also _options was already taken for CLI args and callbacks use _plugin_options instead. ''' # load from config self._plugin_options = C.config.get_plugin_options( get_plugin_class(self), self._load_name, keys=task_keys, variables=var_options, direct=direct)
def set_options(self, task_keys=None, var_options=None, direct=None): ''' This is different than the normal plugin method as callbacks get called early and really don't accept keywords. Also _options was already taken for CLI args and callbacks use _plugin_options instead. ''' # load from config self._plugin_options = C.config.get_plugin_options(get_plugin_class(self), self._load_name, keys=task_keys, variables=var_options) # or parse specific options if direct: for k in direct: if k in self._plugin_options: self.set_option(k, direct[k])
def _load_config_defs(self, name, path): ''' Reads plugin docs to find configuration setting definitions, to push to config manager for later use ''' # plugins w/o class name don't support config if self.class_name: type_name = get_plugin_class(self.class_name) # if type name != 'module_doc_fragment': if type_name in C.CONFIGURABLE_PLUGINS: dstring = get_docstring(path, fragment_loader, verbose=False, ignore_errors=True)[0] if dstring and 'options' in dstring and isinstance(dstring['options'], dict): C.config.initialize_plugin_configuration_definitions(type_name, name, dstring['options']) display.debug('Loaded config def from plugin (%s/%s)' % (type_name, name))
def _load_config_defs(self, name, path): ''' Reads plugin docs to find configuration setting definitions, to push to config manager for later use ''' # plugins w/o class name don't support config if self.class_name: type_name = get_plugin_class(self.class_name) # if type name != 'module_doc_fragment': if type_name in C.CONFIGURABLE_PLUGINS: dstring = get_docstring(path, fragment_loader, verbose=False, ignore_errors=True)[0] if dstring and 'options' in dstring and isinstance(dstring['options'], dict): C.config.initialize_plugin_configuration_definitions(type_name, name, dstring['options']) display.debug('Loaded config def from plugin (%s/%s)' % (type_name, name))
def _load_config_defs(self, name, path): ''' Reads plugin docs to find configuration setting definitions, to push to config manager for later use ''' # plugins w/o class name don't support config if self.class_name: type_name = get_plugin_class(self.class_name) # FIXME: expand from just connection and callback if type_name in ('connection', 'callback'): dstring = read_docstring(path, verbose=False, ignore_errors=False) if dstring.get('doc', False): if 'options' in dstring['doc'] and isinstance(dstring['doc']['options'], dict): C.config.initialize_plugin_configuration_definitions(type_name, name, dstring['doc']['options']) display.debug('Loaded config def from plugin (%s/%s)' % (type_name, name))
def _load_config_defs(self, name, module, path): ''' Reads plugin docs to find configuration setting definitions, to push to config manager for later use ''' # plugins w/o class name don't support config if self.class_name: type_name = get_plugin_class(self.class_name) # if type name != 'module_doc_fragment': if type_name in C.CONFIGURABLE_PLUGINS: dstring = AnsibleLoader(getattr(module, 'DOCUMENTATION', ''), file_name=path).get_single_data() if dstring: add_fragments(dstring, path, fragment_loader=fragment_loader) if dstring and 'options' in dstring and isinstance(dstring['options'], dict): C.config.initialize_plugin_configuration_definitions(type_name, name, dstring['options']) display.debug('Loaded config def from plugin (%s/%s)' % (type_name, name))
def _load_config_defs(self, name, path): ''' Reads plugin docs to find configuration setting definitions, to push to config manager for later use ''' # plugins w/o class name don't support config if self.class_name: type_name = get_plugin_class(self.class_name) # FIXME: expand to other plugins, but never doc fragments # if type name != 'module_doc_fragment': if type_name in ('callback', 'connection', 'inventory', 'lookup', 'shell'): dstring = get_docstring(path, fragment_loader, verbose=False, ignore_errors=True)[0] if dstring and 'options' in dstring and isinstance( dstring['options'], dict): C.config.initialize_plugin_configuration_definitions( type_name, name, dstring['options']) display.debug('Loaded config def from plugin (%s/%s)' % (type_name, name))
def _find_fq_plugin(self, fq_name, extension): fq_name = to_native(fq_name) # prefix our extension Python namespace if it isn't already there if not fq_name.startswith('ansible_collections.'): fq_name = 'ansible_collections.' + fq_name splitname = fq_name.rsplit('.', 1) if len(splitname) != 2: raise ValueError( '{0} is not a valid namespace-qualified plugin name'.format( to_native(fq_name))) package = splitname[0] resource = splitname[1] append_plugin_type = self.class_name or self.subdir if append_plugin_type: # only current non-class special case, module_utils don't use this loader method if append_plugin_type == 'library': append_plugin_type = 'modules' elif append_plugin_type != 'module_utils': append_plugin_type = get_plugin_class(append_plugin_type) package += '.plugins.{0}'.format(append_plugin_type) if extension: resource += extension pkg = sys.modules.get(package) if not pkg: # FIXME: there must be cheaper/safer way to do this pkg = import_module(package) # if the package is one of our flatmaps, we need to consult its loader to find the path, since the file could be # anywhere in the tree if hasattr(pkg, '__loader__') and isinstance(pkg.__loader__, AnsibleFlatMapLoader): try: file_path = pkg.__loader__.find_file(resource) return to_text(file_path) except IOError: # this loader already takes care of extensionless files, so if we didn't find it, just bail return None pkg_path = os.path.dirname(pkg.__file__) resource_path = os.path.join(pkg_path, resource) # FIXME: and is file or file link or ... if os.path.exists(resource_path): return to_text(resource_path) # look for any matching extension in the package location (sans filter) ext_blacklist = ['.pyc', '.pyo'] found_files = [ f for f in glob.iglob(os.path.join(pkg_path, resource) + '.*') if os.path.isfile(f) and os.path.splitext(f)[1] not in ext_blacklist ] if not found_files: return None if len(found_files) > 1: # TODO: warn? pass return to_text(found_files[0])