Making variable names more descriptive for the default variables work

pull/4007/head
James Cammarata 11 years ago
parent 02b7b79d7e
commit 50f54f6bda

@ -170,9 +170,9 @@ class Play(object):
if vars_data:
role_vars = utils.combine_vars(vars_data, role_vars)
defaults = self._resolve_main(utils.path_dwim(self.basedir, os.path.join(role_path, 'defaults')))
defs_data = {}
defaults_data = {}
if os.path.isfile(defaults):
defs_data = utils.parse_yaml_from_file(defaults)
defaults_data = utils.parse_yaml_from_file(defaults)
# 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(role_path, 'meta')))
@ -201,17 +201,17 @@ class Play(object):
if vars_data:
dep_vars = utils.combine_vars(vars_data, dep_vars)
defaults = self._resolve_main(utils.path_dwim(self.basedir, os.path.join(dep_path, 'defaults')))
dep_defs_data = {}
dep_defaults_data = {}
if os.path.isfile(defaults):
dep_defs_data = utils.parse_yaml_from_file(defaults)
dep_defaults_data = utils.parse_yaml_from_file(defaults)
if 'role' in dep_vars:
del dep_vars['role']
self._build_role_dependencies([dep], dep_stack, passed_vars=dep_vars, level=level+1)
dep_stack.append([dep,dep_path,dep_vars,dep_defs_data])
dep_stack.append([dep,dep_path,dep_vars,dep_defaults_data])
# 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_path,role_vars,defs_data])
dep_stack.append([role,role_path,role_vars,defaults_data])
return dep_stack
def _load_role_defaults(self, defaults_files):
@ -257,7 +257,7 @@ class Play(object):
roles = self._build_role_dependencies(roles, [], self.vars)
for (role,role_path,role_vars,def_vars) in roles:
for (role,role_path,role_vars,default_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 = {}
@ -280,7 +280,7 @@ class Play(object):
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" % (role_path, task, handler, vars_file, library))
if os.path.isfile(task):
nt = dict(include=pipes.quote(task), vars=role_vars, def_vars=def_vars)
nt = dict(include=pipes.quote(task), vars=role_vars, default_vars=default_vars)
for k in special_keys:
if k in special_vars:
nt[k] = special_vars[k]
@ -350,7 +350,7 @@ class Play(object):
# *************************************************
def _load_tasks(self, tasks, vars={}, def_vars={}, sudo_vars={}, additional_conditions=[], original_file=None):
def _load_tasks(self, tasks, vars={}, default_vars={}, sudo_vars={}, additional_conditions=[], original_file=None):
''' handle task and handler include statements '''
results = []
@ -396,12 +396,12 @@ class Play(object):
included_additional_conditions.insert(0, utils.compile_when_to_only_if("%s %s" % (k[5:], x[k])))
elif k == 'when':
included_additional_conditions.insert(0, utils.compile_when_to_only_if("jinja2_compare %s" % x[k]))
elif k in ("include", "vars", "def_vars", "only_if", "sudo", "sudo_user"):
elif k in ("include", "vars", "default_vars", "only_if", "sudo", "sudo_user"):
pass
else:
raise errors.AnsibleError("parse error: task includes cannot be used with other directives: %s" % k)
def_vars = utils.combine_vars(self.default_vars, x.get('def_vars', {}))
default_vars = utils.combine_vars(self.default_vars, x.get('default_vars', {}))
if 'vars' in x:
task_vars = utils.combine_vars(task_vars, x['vars'])
if 'only_if' in x:
@ -419,9 +419,9 @@ class Play(object):
include_file = template(dirname, tokens[0], mv)
include_filename = utils.path_dwim(dirname, include_file)
data = utils.parse_yaml_from_file(include_filename)
results += self._load_tasks(data, mv, def_vars, included_sudo_vars, included_additional_conditions, original_file=include_filename)
results += self._load_tasks(data, mv, default_vars, included_sudo_vars, included_additional_conditions, original_file=include_filename)
elif type(x) == dict:
results.append(Task(self,x,module_vars=task_vars,default_vars=def_vars,additional_conditions=additional_conditions))
results.append(Task(self,x,module_vars=task_vars,default_vars=default_vars,additional_conditions=additional_conditions))
else:
raise Exception("unexpected task type")

Loading…
Cancel
Save