1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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
This commit is contained in:
Thomas Omans 2013-09-27 10:03:28 -07:00 committed by Michael DeHaan
parent 43df00550d
commit 632232259a
3 changed files with 23 additions and 9 deletions

View file

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

View file

@ -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, '*')

View file

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