Example #1
0
def _rewrite_yaml_mapping_keys_non_vars(el, namespace, collection, spec):
    translate = []
    for key in el.keys():
        if is_reserved_name(key):
            continue

        prefix = 'with_'
        if prefix in key:
            prefix_len = len(prefix)

            if not key.startswith(prefix):
                continue
            plugin_name = key[prefix_len:]
            try:
                plugin_collection = get_plugin_collection(plugin_name, 'lookup', spec)
                translate.append((prefix + get_plugin_fqcn(namespace, plugin_collection, plugin_name), key))
                integration_tests_add_to_deps(collection, plugin_collection)
            except LookupError:
                pass

        for coll in spec[namespace].keys():
            try:
                modules_in_collection = get_plugins_from_collection(namespace, coll, 'modules', spec)
            except LookupError:
                continue

            for module in modules_in_collection:
                if key != module:
                    continue
                new_module_name = get_plugin_fqcn(namespace, coll, key)
                translate.append((new_module_name, key))
                integration_tests_add_to_deps(collection, coll)

    for new_key, old_key in translate:
        el[new_key] = el.pop(old_key)
Example #2
0
    def find_plugin(self, name, mod_type='', ignore_deprecated=False, check_aliases=False):
        ''' Find a plugin named name '''

        # Import here to avoid circular import
        from ansible.vars.reserved import is_reserved_name

        plugin = self._find_plugin(name, mod_type=mod_type, ignore_deprecated=ignore_deprecated, check_aliases=check_aliases)
        if plugin and self.package == 'ansible.modules' and is_reserved_name(name):
            raise AnsibleError(
                'Module "%s" shadows the name of a reserved keyword. Please rename or remove this module. Found at %s' % (name, plugin)
            )

        return plugin
Example #3
0
def _rewrite_yaml_mapping_keys(el, namespace, collection, spec):
    for key in el.keys():
        if is_reserved_name(key):
            continue

        plugin_type = KEYWORD_TO_PLUGIN_MAP.get(key)
        if plugin_type is None:
            continue

        try:
            plugin_collection = get_plugin_collection(el[key], plugin_type, spec)
            el[key] = get_plugin_fqcn(namespace, plugin_collection, el[key])
            integration_tests_add_to_deps(collection, plugin_collection)
        except LookupError:
            if '{{' in el[key]:
                add_manual_check(key, el[key])
Example #4
0
    def find_plugin(self, name, mod_type='', ignore_deprecated=False, check_aliases=False):
        ''' Find a plugin named name '''

        # Import here to avoid circular import
        from ansible.vars.reserved import is_reserved_name

        plugin = self._find_plugin(name, mod_type=mod_type, ignore_deprecated=ignore_deprecated, check_aliases=check_aliases)
        if plugin and self.package == 'ansible.modules' and name not in ('gather_facts',) and is_reserved_name(name):
            raise AnsibleError(
                'Module "%s" shadows the name of a reserved keyword. Please rename or remove this module. Found at %s' % (name, plugin)
            )

        return plugin