diff --git a/v2/ansible/playbook/role/definition.py b/v2/ansible/playbook/role/definition.py index 9f2a7ed4db8..841d081af79 100644 --- a/v2/ansible/playbook/role/definition.py +++ b/v2/ansible/playbook/role/definition.py @@ -38,9 +38,10 @@ class RoleDefinition(Base, Conditional, Taggable): _role = FieldAttribute(isa='string') - def __init__(self, role_path=None): - self._role_path = role_path - self._role_params = dict() + def __init__(self, role_basedir=None): + self._role_path = None + self._role_basedir = role_basedir + self._role_params = dict() super(RoleDefinition, self).__init__() def __repr__(self): @@ -112,17 +113,18 @@ class RoleDefinition(Base, Conditional, Taggable): ''' # FIXME: this should use unfrackpath once the utils code has been sorted out - if self._role_path: - role_path = self._role_path - else: - role_path = os.path.normpath(role_name) + role_path = os.path.normpath(role_name) if self._loader.path_exists(role_path): role_name = os.path.basename(role_name) return (role_name, role_path) else: # FIXME: this should search in the configured roles path - for path in (os.path.join(self._loader.get_basedir(), 'roles'), './roles', '/etc/ansible/roles'): + role_search_paths = [os.path.join(self._loader.get_basedir(), 'roles'), './roles', '/etc/ansible/roles'] + if self._role_basedir: + role_search_paths = [self._role_basedir] + role_search_paths + + for path in role_search_paths: role_path = os.path.join(path, role_name) if self._loader.path_exists(role_path): return (role_name, role_path) @@ -131,7 +133,6 @@ class RoleDefinition(Base, Conditional, Taggable): # in the yaml so the error line/file can be reported # here - #import epdb; epdb.st() raise AnsibleError("the role '%s' was not found" % role_name) def _split_role_params(self, ds): diff --git a/v2/ansible/playbook/role/include.py b/v2/ansible/playbook/role/include.py index 4d390500748..b063aecc350 100644 --- a/v2/ansible/playbook/role/include.py +++ b/v2/ansible/playbook/role/include.py @@ -37,13 +37,13 @@ class RoleInclude(RoleDefinition): FIXME: docstring """ - def __init__(self, role_path=None): - super(RoleInclude, self).__init__(role_path=role_path) + def __init__(self, role_basedir=None): + super(RoleInclude, self).__init__(role_basedir=role_basedir) @staticmethod def load(data, current_role_path=None, parent_role=None, variable_manager=None, loader=None): assert isinstance(data, string_types) or isinstance(data, dict) - ri = RoleInclude(role_path=current_role_path) + ri = RoleInclude(role_basedir=current_role_path) return ri.load_data(data, variable_manager=variable_manager, loader=loader)