Fix roles_path loading in v2

pull/10122/head
James Cammarata 10 years ago
parent ed05db52ba
commit 181dd058eb

@ -23,6 +23,7 @@ from six import iteritems, string_types
import os import os
from ansible import constants as C
from ansible.errors import AnsibleError from ansible.errors import AnsibleError
from ansible.parsing.yaml.objects import AnsibleBaseYAMLObject, AnsibleMapping from ansible.parsing.yaml.objects import AnsibleBaseYAMLObject, AnsibleMapping
from ansible.playbook.attribute import Attribute, FieldAttribute from ansible.playbook.attribute import Attribute, FieldAttribute
@ -119,8 +120,18 @@ class RoleDefinition(Base, Conditional, Taggable):
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 # we always start the search for roles in the base directory of the playbook
role_search_paths = [os.path.join(self._loader.get_basedir(), 'roles'), './roles', '/etc/ansible/roles'] role_search_paths = [os.path.join(self._loader.get_basedir(), 'roles'), './roles']
# also search in the configured roles path
configured_paths = C.DEFAULT_ROLES_PATH
if ':' in configured_paths:
configured_paths = configured_paths.split(':')
role_search_paths.extend(configured_paths)
else:
role_search_paths.append(configured_paths)
print("role search paths are: %s" % role_search_paths)
if self._role_basedir: if self._role_basedir:
role_search_paths = [self._role_basedir] + role_search_paths role_search_paths = [self._role_basedir] + role_search_paths
@ -129,9 +140,8 @@ class RoleDefinition(Base, Conditional, Taggable):
if self._loader.path_exists(role_path): if self._loader.path_exists(role_path):
return (role_name, role_path) return (role_name, role_path)
# FIXME: make the parser smart about list/string entries # FIXME: make the parser smart about list/string entries in
# in the yaml so the error line/file can be reported # the yaml so the error line/file can be reported here
# here
raise AnsibleError("the role '%s' was not found" % role_name) raise AnsibleError("the role '%s' was not found" % role_name)

Loading…
Cancel
Save