Adding config flag role_path for common/global roles

Using ANSIBLE_ROLE_PATH environment variable or role_path in ansible.cfg
can configure paths where roles will be searched for
extra paths will only be used as a backup once regular locations are exhausted
pull/4278/merge
Thomas Omans 11 years ago committed by Michael DeHaan
parent 43df00550d
commit 632232259a

@ -12,6 +12,7 @@
hostfile = /etc/ansible/hosts hostfile = /etc/ansible/hosts
library = /usr/share/ansible library = /usr/share/ansible
#roles_path = /etc/ansible/roles
remote_tmp = $HOME/.ansible/tmp remote_tmp = $HOME/.ansible/tmp
pattern = * pattern = *
forks = 5 forks = 5

@ -95,6 +95,7 @@ DEFAULTS='defaults'
# configurable things # configurable things
DEFAULT_HOST_LIST = shell_expand_path(get_config(p, DEFAULTS, 'hostfile', 'ANSIBLE_HOSTS', '/etc/ansible/hosts')) DEFAULT_HOST_LIST = shell_expand_path(get_config(p, DEFAULTS, 'hostfile', 'ANSIBLE_HOSTS', '/etc/ansible/hosts'))
DEFAULT_MODULE_PATH = get_config(p, DEFAULTS, 'library', 'ANSIBLE_LIBRARY', DIST_MODULE_PATH) DEFAULT_MODULE_PATH = get_config(p, DEFAULTS, 'library', 'ANSIBLE_LIBRARY', DIST_MODULE_PATH)
DEFAULT_ROLES_PATH = get_config(p, DEFAULTS, 'roles_path', 'ANSIBLE_ROLES_PATH', None)
DEFAULT_REMOTE_TMP = shell_expand_path(get_config(p, DEFAULTS, 'remote_tmp', 'ANSIBLE_REMOTE_TEMP', '$HOME/.ansible/tmp')) DEFAULT_REMOTE_TMP = shell_expand_path(get_config(p, DEFAULTS, 'remote_tmp', 'ANSIBLE_REMOTE_TEMP', '$HOME/.ansible/tmp'))
DEFAULT_MODULE_NAME = get_config(p, DEFAULTS, 'module_name', None, 'command') DEFAULT_MODULE_NAME = get_config(p, DEFAULTS, 'module_name', None, 'command')
DEFAULT_PATTERN = get_config(p, DEFAULTS, 'pattern', None, '*') DEFAULT_PATTERN = get_config(p, DEFAULTS, 'pattern', None, '*')

@ -21,6 +21,7 @@ from ansible.utils.template import template
from ansible import utils from ansible import utils
from ansible import errors from ansible import errors
from ansible.playbook.task import Task from ansible.playbook.task import Task
import ansible.constants as C
import pipes import pipes
import shlex import shlex
import os import os
@ -148,16 +149,27 @@ class Play(object):
role_vars = orig_path role_vars = orig_path
orig_path = role_name orig_path = role_name
path = utils.path_dwim(self.basedir, os.path.join('roles', orig_path)) role_path = None
if not os.path.isdir(path) and not orig_path.startswith(".") and not orig_path.startswith("/"):
path2 = utils.path_dwim(self.basedir, orig_path)
if not os.path.isdir(path2):
raise errors.AnsibleError("cannot find role in %s or %s" % (path, path2))
path = path2
elif not os.path.isdir(path):
raise errors.AnsibleError("cannot find role in %s" % (path))
return (path, role_vars) possible_paths = [
utils.path_dwim(self.basedir, os.path.join('roles', orig_path)),
utils.path_dwim(self.basedir, orig_path)
]
if C.DEFAULT_ROLES_PATH:
search_locations = C.DEFAULT_ROLES_PATH.split(os.pathsep)
for loc in search_locations:
possible_paths.append(utils.path_dwim(loc, orig_path))
for path_option in possible_paths:
if os.path.isdir(path_option):
role_path = path_option
break
if role_path is None:
raise errors.AnsibleError("cannot find role in %s" % " or ".join(possible_paths))
return (role_path, role_vars)
def _build_role_dependencies(self, roles, dep_stack, passed_vars={}, level=0): def _build_role_dependencies(self, roles, dep_stack, passed_vars={}, level=0):
# this number is arbitrary, but it seems sane # this number is arbitrary, but it seems sane

Loading…
Cancel
Save