fixing bug with role paths
This commit is contained in:
parent
fd67a20787
commit
0823fb2cd9
2 changed files with 13 additions and 12 deletions
|
@ -38,9 +38,10 @@ class RoleDefinition(Base, Conditional, Taggable):
|
||||||
|
|
||||||
_role = FieldAttribute(isa='string')
|
_role = FieldAttribute(isa='string')
|
||||||
|
|
||||||
def __init__(self, role_path=None):
|
def __init__(self, role_basedir=None):
|
||||||
self._role_path = role_path
|
self._role_path = None
|
||||||
self._role_params = dict()
|
self._role_basedir = role_basedir
|
||||||
|
self._role_params = dict()
|
||||||
super(RoleDefinition, self).__init__()
|
super(RoleDefinition, self).__init__()
|
||||||
|
|
||||||
def __repr__(self):
|
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
|
# FIXME: this should use unfrackpath once the utils code has been sorted out
|
||||||
if self._role_path:
|
role_path = os.path.normpath(role_name)
|
||||||
role_path = self._role_path
|
|
||||||
else:
|
|
||||||
role_path = os.path.normpath(role_name)
|
|
||||||
|
|
||||||
if self._loader.path_exists(role_path):
|
if self._loader.path_exists(role_path):
|
||||||
role_name = os.path.basename(role_name)
|
role_name = os.path.basename(role_name)
|
||||||
return (role_name, role_path)
|
return (role_name, role_path)
|
||||||
else:
|
else:
|
||||||
# FIXME: this should search in the configured roles path
|
# 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)
|
role_path = os.path.join(path, role_name)
|
||||||
if self._loader.path_exists(role_path):
|
if self._loader.path_exists(role_path):
|
||||||
return (role_name, 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
|
# in the yaml so the error line/file can be reported
|
||||||
# here
|
# here
|
||||||
|
|
||||||
#import epdb; epdb.st()
|
|
||||||
raise AnsibleError("the role '%s' was not found" % role_name)
|
raise AnsibleError("the role '%s' was not found" % role_name)
|
||||||
|
|
||||||
def _split_role_params(self, ds):
|
def _split_role_params(self, ds):
|
||||||
|
|
|
@ -37,13 +37,13 @@ class RoleInclude(RoleDefinition):
|
||||||
FIXME: docstring
|
FIXME: docstring
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, role_path=None):
|
def __init__(self, role_basedir=None):
|
||||||
super(RoleInclude, self).__init__(role_path=role_path)
|
super(RoleInclude, self).__init__(role_basedir=role_basedir)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def load(data, current_role_path=None, parent_role=None, variable_manager=None, loader=None):
|
def load(data, current_role_path=None, parent_role=None, variable_manager=None, loader=None):
|
||||||
assert isinstance(data, string_types) or isinstance(data, dict)
|
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)
|
return ri.load_data(data, variable_manager=variable_manager, loader=loader)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue