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

Small cleanup, no need to call _get_role_path a second time

This commit is contained in:
James Cammarata 2013-08-15 00:50:08 -05:00
parent 9a401e73a6
commit e12b99dba6

View file

@ -152,10 +152,10 @@ class Play(object):
if level > 20:
raise errors.AnsibleError("too many levels of recursion while resolving role dependencies")
for role in roles:
path,role_vars = self._get_role_path(role)
role_path,role_vars = self._get_role_path(role)
# the meta directory contains the yaml that should
# hold the list of dependencies (if any)
meta = self._resolve_main(utils.path_dwim(self.basedir, os.path.join(path, 'meta')))
meta = self._resolve_main(utils.path_dwim(self.basedir, os.path.join(role_path, 'meta')))
if os.path.isfile(meta):
data = utils.parse_yaml_from_file(meta)
if data:
@ -169,11 +169,11 @@ class Play(object):
if 'role' in dep_vars:
del dep_vars['role']
self._build_role_dependencies([dep], dep_stack, vars=dep_vars, level=level+1)
dep_stack.append([dep,dep_vars])
dep_stack.append([dep,dep_path,dep_vars])
# only add the current role when we're at the top level,
# otherwise we'll end up in a recursive loop
if level == 0:
dep_stack.append([role,role_vars])
dep_stack.append([role,role_path,role_vars])
return dep_stack
def _load_roles(self, roles, ds):
@ -204,9 +204,7 @@ class Play(object):
roles = self._build_role_dependencies(roles, [], self.vars)
for role,role_vars in roles:
path,ignore = self._get_role_path(role)
for role,role_path,role_vars in roles:
# special vars must be extracted from the dict to the included tasks
special_keys = [ "sudo", "sudo_user", "when", "with_items" ]
special_vars = {}
@ -214,17 +212,17 @@ class Play(object):
if k in role_vars:
special_vars[k] = role_vars[k]
task_basepath = utils.path_dwim(self.basedir, os.path.join(path, 'tasks'))
handler_basepath = utils.path_dwim(self.basedir, os.path.join(path, 'handlers'))
vars_basepath = utils.path_dwim(self.basedir, os.path.join(path, 'vars'))
task_basepath = utils.path_dwim(self.basedir, os.path.join(role_path, 'tasks'))
handler_basepath = utils.path_dwim(self.basedir, os.path.join(role_path, 'handlers'))
vars_basepath = utils.path_dwim(self.basedir, os.path.join(role_path, 'vars'))
task = self._resolve_main(task_basepath)
handler = self._resolve_main(handler_basepath)
vars_file = self._resolve_main(vars_basepath)
library = utils.path_dwim(self.basedir, os.path.join(path, 'library'))
library = utils.path_dwim(self.basedir, os.path.join(role_path, 'library'))
if not os.path.isfile(task) and not os.path.isfile(handler) and not os.path.isfile(vars_file) and not os.path.isdir(library):
raise errors.AnsibleError("found role at %s, but cannot find %s or %s or %s or %s" % (path, task, handler, vars_file, library))
raise errors.AnsibleError("found role at %s, but cannot find %s or %s or %s or %s" % (role_path, task, handler, vars_file, library))
if os.path.isfile(task):
nt = dict(include=pipes.quote(task), vars=role_vars)
for k in special_keys: