|
|
@ -33,7 +33,7 @@ import uuid
|
|
|
|
class Play(object):
|
|
|
|
class Play(object):
|
|
|
|
|
|
|
|
|
|
|
|
__slots__ = [
|
|
|
|
__slots__ = [
|
|
|
|
'hosts', 'name', 'vars', 'default_vars', 'vars_prompt', 'vars_files',
|
|
|
|
'hosts', 'name', 'vars', 'vars_file_vars', 'role_vars', 'default_vars', 'vars_prompt', 'vars_files',
|
|
|
|
'handlers', 'remote_user', 'remote_port', 'included_roles', 'accelerate',
|
|
|
|
'handlers', 'remote_user', 'remote_port', 'included_roles', 'accelerate',
|
|
|
|
'accelerate_port', 'accelerate_ipv6', 'sudo', 'sudo_user', 'transport', 'playbook',
|
|
|
|
'accelerate_port', 'accelerate_ipv6', 'sudo', 'sudo_user', 'transport', 'playbook',
|
|
|
|
'tags', 'gather_facts', 'serial', '_ds', '_handlers', '_tasks',
|
|
|
|
'tags', 'gather_facts', 'serial', '_ds', '_handlers', '_tasks',
|
|
|
@ -65,6 +65,8 @@ class Play(object):
|
|
|
|
self.vars_prompt = ds.get('vars_prompt', {})
|
|
|
|
self.vars_prompt = ds.get('vars_prompt', {})
|
|
|
|
self.playbook = playbook
|
|
|
|
self.playbook = playbook
|
|
|
|
self.vars = self._get_vars()
|
|
|
|
self.vars = self._get_vars()
|
|
|
|
|
|
|
|
self.vars_file_vars = dict() # these are vars read in from vars_files:
|
|
|
|
|
|
|
|
self.role_vars = dict() # these are vars read in from vars/main.yml files in roles
|
|
|
|
self.basedir = basedir
|
|
|
|
self.basedir = basedir
|
|
|
|
self.roles = ds.get('roles', None)
|
|
|
|
self.roles = ds.get('roles', None)
|
|
|
|
self.tags = ds.get('tags', None)
|
|
|
|
self.tags = ds.get('tags', None)
|
|
|
@ -108,10 +110,6 @@ class Play(object):
|
|
|
|
|
|
|
|
|
|
|
|
self._update_vars_files_for_host(None)
|
|
|
|
self._update_vars_files_for_host(None)
|
|
|
|
|
|
|
|
|
|
|
|
# apply any extra_vars specified on the command line now
|
|
|
|
|
|
|
|
if type(self.playbook.extra_vars) == dict:
|
|
|
|
|
|
|
|
self.vars = utils.combine_vars(self.vars, self.playbook.extra_vars)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# template everything to be efficient, but do not pre-mature template
|
|
|
|
# template everything to be efficient, but do not pre-mature template
|
|
|
|
# tasks/handlers as they may have inventory scope overrides
|
|
|
|
# tasks/handlers as they may have inventory scope overrides
|
|
|
|
_tasks = ds.pop('tasks', [])
|
|
|
|
_tasks = ds.pop('tasks', [])
|
|
|
@ -224,6 +222,7 @@ class Play(object):
|
|
|
|
for role in roles:
|
|
|
|
for role in roles:
|
|
|
|
role_path,role_vars = self._get_role_path(role)
|
|
|
|
role_path,role_vars = self._get_role_path(role)
|
|
|
|
role_vars = utils.combine_vars(passed_vars, role_vars)
|
|
|
|
role_vars = utils.combine_vars(passed_vars, role_vars)
|
|
|
|
|
|
|
|
|
|
|
|
vars = self._resolve_main(utils.path_dwim(self.basedir, os.path.join(role_path, 'vars')))
|
|
|
|
vars = self._resolve_main(utils.path_dwim(self.basedir, os.path.join(role_path, 'vars')))
|
|
|
|
vars_data = {}
|
|
|
|
vars_data = {}
|
|
|
|
if os.path.isfile(vars):
|
|
|
|
if os.path.isfile(vars):
|
|
|
@ -232,10 +231,12 @@ class Play(object):
|
|
|
|
if not isinstance(vars_data, dict):
|
|
|
|
if not isinstance(vars_data, dict):
|
|
|
|
raise errors.AnsibleError("vars from '%s' are not a dict" % vars)
|
|
|
|
raise errors.AnsibleError("vars from '%s' are not a dict" % vars)
|
|
|
|
role_vars = utils.combine_vars(vars_data, role_vars)
|
|
|
|
role_vars = utils.combine_vars(vars_data, role_vars)
|
|
|
|
|
|
|
|
|
|
|
|
defaults = self._resolve_main(utils.path_dwim(self.basedir, os.path.join(role_path, 'defaults')))
|
|
|
|
defaults = self._resolve_main(utils.path_dwim(self.basedir, os.path.join(role_path, 'defaults')))
|
|
|
|
defaults_data = {}
|
|
|
|
defaults_data = {}
|
|
|
|
if os.path.isfile(defaults):
|
|
|
|
if os.path.isfile(defaults):
|
|
|
|
defaults_data = utils.parse_yaml_from_file(defaults, vault_password=self.vault_password)
|
|
|
|
defaults_data = utils.parse_yaml_from_file(defaults, vault_password=self.vault_password)
|
|
|
|
|
|
|
|
|
|
|
|
# the meta directory contains the yaml that should
|
|
|
|
# the meta directory contains the yaml that should
|
|
|
|
# hold the list of dependencies (if any)
|
|
|
|
# hold the list of dependencies (if any)
|
|
|
|
meta = self._resolve_main(utils.path_dwim(self.basedir, os.path.join(role_path, 'meta')))
|
|
|
|
meta = self._resolve_main(utils.path_dwim(self.basedir, os.path.join(role_path, 'meta')))
|
|
|
@ -287,13 +288,15 @@ class Play(object):
|
|
|
|
|
|
|
|
|
|
|
|
dep_vars = utils.combine_vars(passed_vars, dep_vars)
|
|
|
|
dep_vars = utils.combine_vars(passed_vars, dep_vars)
|
|
|
|
dep_vars = utils.combine_vars(role_vars, dep_vars)
|
|
|
|
dep_vars = utils.combine_vars(role_vars, dep_vars)
|
|
|
|
|
|
|
|
|
|
|
|
vars = self._resolve_main(utils.path_dwim(self.basedir, os.path.join(dep_path, 'vars')))
|
|
|
|
vars = self._resolve_main(utils.path_dwim(self.basedir, os.path.join(dep_path, 'vars')))
|
|
|
|
vars_data = {}
|
|
|
|
vars_data = {}
|
|
|
|
if os.path.isfile(vars):
|
|
|
|
if os.path.isfile(vars):
|
|
|
|
vars_data = utils.parse_yaml_from_file(vars, vault_password=self.vault_password)
|
|
|
|
vars_data = utils.parse_yaml_from_file(vars, vault_password=self.vault_password)
|
|
|
|
if vars_data:
|
|
|
|
if vars_data:
|
|
|
|
#dep_vars = utils.combine_vars(vars_data, dep_vars)
|
|
|
|
|
|
|
|
dep_vars = utils.combine_vars(dep_vars, vars_data)
|
|
|
|
dep_vars = utils.combine_vars(dep_vars, vars_data)
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
defaults = self._resolve_main(utils.path_dwim(self.basedir, os.path.join(dep_path, 'defaults')))
|
|
|
|
defaults = self._resolve_main(utils.path_dwim(self.basedir, os.path.join(dep_path, 'defaults')))
|
|
|
|
dep_defaults_data = {}
|
|
|
|
dep_defaults_data = {}
|
|
|
|
if os.path.isfile(defaults):
|
|
|
|
if os.path.isfile(defaults):
|
|
|
@ -338,6 +341,19 @@ class Play(object):
|
|
|
|
dep_stack.append([role,role_path,role_vars,defaults_data])
|
|
|
|
dep_stack.append([role,role_path,role_vars,defaults_data])
|
|
|
|
return dep_stack
|
|
|
|
return dep_stack
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _load_role_vars_files(self, vars_files):
|
|
|
|
|
|
|
|
# process variables stored in vars/main.yml files
|
|
|
|
|
|
|
|
role_vars = {}
|
|
|
|
|
|
|
|
for filename in vars_files:
|
|
|
|
|
|
|
|
if os.path.exists(filename):
|
|
|
|
|
|
|
|
new_vars = utils.parse_yaml_from_file(filename, vault_password=self.vault_password)
|
|
|
|
|
|
|
|
if new_vars:
|
|
|
|
|
|
|
|
if type(new_vars) != dict:
|
|
|
|
|
|
|
|
raise errors.AnsibleError("%s must be stored as dictionary/hash: %s" % (filename, type(new_vars)))
|
|
|
|
|
|
|
|
role_vars = utils.combine_vars(role_vars, new_vars)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return role_vars
|
|
|
|
|
|
|
|
|
|
|
|
def _load_role_defaults(self, defaults_files):
|
|
|
|
def _load_role_defaults(self, defaults_files):
|
|
|
|
# process default variables
|
|
|
|
# process default variables
|
|
|
|
default_vars = {}
|
|
|
|
default_vars = {}
|
|
|
@ -366,7 +382,7 @@ class Play(object):
|
|
|
|
|
|
|
|
|
|
|
|
new_tasks = []
|
|
|
|
new_tasks = []
|
|
|
|
new_handlers = []
|
|
|
|
new_handlers = []
|
|
|
|
new_vars_files = []
|
|
|
|
role_vars_files = []
|
|
|
|
defaults_files = []
|
|
|
|
defaults_files = []
|
|
|
|
|
|
|
|
|
|
|
|
pre_tasks = ds.get('pre_tasks', None)
|
|
|
|
pre_tasks = ds.get('pre_tasks', None)
|
|
|
@ -434,7 +450,7 @@ class Play(object):
|
|
|
|
nt[k] = special_vars[k]
|
|
|
|
nt[k] = special_vars[k]
|
|
|
|
new_handlers.append(nt)
|
|
|
|
new_handlers.append(nt)
|
|
|
|
if os.path.isfile(vars_file):
|
|
|
|
if os.path.isfile(vars_file):
|
|
|
|
new_vars_files.append(vars_file)
|
|
|
|
role_vars_files.append(vars_file)
|
|
|
|
if os.path.isfile(defaults_file):
|
|
|
|
if os.path.isfile(defaults_file):
|
|
|
|
defaults_files.append(defaults_file)
|
|
|
|
defaults_files.append(defaults_file)
|
|
|
|
if os.path.isdir(library):
|
|
|
|
if os.path.isdir(library):
|
|
|
@ -462,13 +478,12 @@ class Play(object):
|
|
|
|
new_tasks.append(dict(meta='flush_handlers'))
|
|
|
|
new_tasks.append(dict(meta='flush_handlers'))
|
|
|
|
|
|
|
|
|
|
|
|
new_handlers.extend(handlers)
|
|
|
|
new_handlers.extend(handlers)
|
|
|
|
new_vars_files.extend(vars_files)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ds['tasks'] = new_tasks
|
|
|
|
ds['tasks'] = new_tasks
|
|
|
|
ds['handlers'] = new_handlers
|
|
|
|
ds['handlers'] = new_handlers
|
|
|
|
ds['vars_files'] = new_vars_files
|
|
|
|
|
|
|
|
ds['role_names'] = role_names
|
|
|
|
ds['role_names'] = role_names
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.role_vars = self._load_role_vars_files(role_vars_files)
|
|
|
|
self.default_vars = self._load_role_defaults(defaults_files)
|
|
|
|
self.default_vars = self._load_role_defaults(defaults_files)
|
|
|
|
|
|
|
|
|
|
|
|
return ds
|
|
|
|
return ds
|
|
|
@ -535,8 +550,7 @@ class Play(object):
|
|
|
|
results.append(Task(self, x))
|
|
|
|
results.append(Task(self, x))
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
task_vars = self.vars.copy()
|
|
|
|
task_vars = vars.copy()
|
|
|
|
task_vars.update(vars)
|
|
|
|
|
|
|
|
if original_file:
|
|
|
|
if original_file:
|
|
|
|
task_vars['_original_file'] = original_file
|
|
|
|
task_vars['_original_file'] = original_file
|
|
|
|
|
|
|
|
|
|
|
@ -601,6 +615,9 @@ class Play(object):
|
|
|
|
task = Task(
|
|
|
|
task = Task(
|
|
|
|
self, x,
|
|
|
|
self, x,
|
|
|
|
module_vars=task_vars,
|
|
|
|
module_vars=task_vars,
|
|
|
|
|
|
|
|
play_vars=self.vars,
|
|
|
|
|
|
|
|
play_file_vars=self.vars_file_vars,
|
|
|
|
|
|
|
|
role_vars=self.role_vars,
|
|
|
|
default_vars=default_vars,
|
|
|
|
default_vars=default_vars,
|
|
|
|
additional_conditions=list(additional_conditions),
|
|
|
|
additional_conditions=list(additional_conditions),
|
|
|
|
role_name=role_name
|
|
|
|
role_name=role_name
|
|
|
@ -818,7 +835,7 @@ class Play(object):
|
|
|
|
target_filename = filename4
|
|
|
|
target_filename = filename4
|
|
|
|
update_vars_cache(host, data, target_filename=target_filename)
|
|
|
|
update_vars_cache(host, data, target_filename=target_filename)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
self.vars = utils.combine_vars(self.vars, data)
|
|
|
|
self.vars_file_vars = utils.combine_vars(self.vars_file_vars, data)
|
|
|
|
# we did process this file
|
|
|
|
# we did process this file
|
|
|
|
return True
|
|
|
|
return True
|
|
|
|
# we did not process this file
|
|
|
|
# we did not process this file
|
|
|
|