fixing bug with role paths

This commit is contained in:
James Cammarata 2015-01-07 13:54:09 -06:00
parent fd67a20787
commit 0823fb2cd9
2 changed files with 13 additions and 12 deletions

View file

@ -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):

View file

@ -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)