mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Allow default variables to be overridden by inventory variables
This commit is contained in:
parent
f66683863e
commit
637d3070dc
4 changed files with 13 additions and 11 deletions
|
@ -307,7 +307,7 @@ class PlayBook(object):
|
|||
remote_pass=self.remote_pass, module_path=self.module_path,
|
||||
timeout=self.timeout, remote_user=task.play.remote_user,
|
||||
remote_port=task.play.remote_port, module_vars=task.module_vars,
|
||||
private_key_file=self.private_key_file,
|
||||
default_vars=task.default_vars, private_key_file=self.private_key_file,
|
||||
setup_cache=self.SETUP_CACHE, basedir=task.play.basedir,
|
||||
conditional=task.only_if, callbacks=self.runner_callbacks,
|
||||
sudo=task.sudo, sudo_user=task.sudo_user,
|
||||
|
@ -447,7 +447,7 @@ class PlayBook(object):
|
|||
remote_pass=self.remote_pass, remote_port=play.remote_port, private_key_file=self.private_key_file,
|
||||
setup_cache=self.SETUP_CACHE, callbacks=self.runner_callbacks, sudo=play.sudo, sudo_user=play.sudo_user,
|
||||
transport=play.transport, sudo_pass=self.sudo_pass, is_playbook=True, module_vars=play.vars,
|
||||
check=self.check, diff=self.diff
|
||||
default_vars=play.default_vars, check=self.check, diff=self.diff
|
||||
).run()
|
||||
self.stats.compute(setup_results, setup=True)
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ import os
|
|||
class Play(object):
|
||||
|
||||
__slots__ = [
|
||||
'hosts', 'name', 'vars', 'vars_prompt', 'vars_files',
|
||||
'hosts', 'name', 'vars', 'default_vars', 'vars_prompt', 'vars_files',
|
||||
'handlers', 'remote_user', 'remote_port',
|
||||
'sudo', 'sudo_user', 'transport', 'playbook',
|
||||
'tags', 'gather_facts', 'serial', '_ds', '_handlers', '_tasks',
|
||||
|
@ -295,10 +295,7 @@ class Play(object):
|
|||
ds['handlers'] = new_handlers
|
||||
ds['vars_files'] = new_vars_files
|
||||
|
||||
defaults = self._load_role_defaults(defaults_files)
|
||||
# merge default vars with self.vars, with vars taking precedence.
|
||||
if defaults:
|
||||
self.vars = utils.combine_vars(defaults, self.vars)
|
||||
self.default_vars = self._load_role_defaults(defaults_files)
|
||||
|
||||
return ds
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ class Task(object):
|
|||
|
||||
__slots__ = [
|
||||
'name', 'meta', 'action', 'only_if', 'when', 'async_seconds', 'async_poll_interval',
|
||||
'notify', 'module_name', 'module_args', 'module_vars',
|
||||
'notify', 'module_name', 'module_args', 'module_vars', 'default_vars',
|
||||
'play', 'notified_by', 'tags', 'register',
|
||||
'delegate_to', 'first_available_file', 'ignore_errors',
|
||||
'local_action', 'transport', 'sudo', 'sudo_user', 'sudo_pass',
|
||||
|
@ -102,6 +102,7 @@ class Task(object):
|
|||
|
||||
self.module_vars = module_vars
|
||||
self.play = play
|
||||
self.default_vars = play.default_vars
|
||||
|
||||
# load various attributes
|
||||
self.name = ds.get('name', None)
|
||||
|
|
|
@ -131,6 +131,7 @@ class Runner(object):
|
|||
sudo=False, # whether to run sudo or not
|
||||
sudo_user=C.DEFAULT_SUDO_USER, # ex: 'root'
|
||||
module_vars=None, # a playbooks internals thing
|
||||
default_vars=None, # ditto
|
||||
is_playbook=False, # running from playbook or not?
|
||||
inventory=None, # reference to Inventory object
|
||||
subset=None, # subset pattern
|
||||
|
@ -159,6 +160,7 @@ class Runner(object):
|
|||
self.inventory = utils.default(inventory, lambda: ansible.inventory.Inventory(host_list))
|
||||
|
||||
self.module_vars = utils.default(module_vars, lambda: {})
|
||||
self.default_vars = utils.default(default_vars, lambda: {})
|
||||
self.always_run = None
|
||||
self.connector = connection.Connection(self)
|
||||
self.conditional = conditional
|
||||
|
@ -405,6 +407,7 @@ class Runner(object):
|
|||
port = self.remote_port
|
||||
|
||||
inject = {}
|
||||
inject = utils.combine_vars(inject, self.default_vars)
|
||||
inject = utils.combine_vars(inject, host_variables)
|
||||
inject = utils.combine_vars(inject, self.module_vars)
|
||||
inject = utils.combine_vars(inject, self.setup_cache[host])
|
||||
|
@ -413,6 +416,7 @@ class Runner(object):
|
|||
inject['group_names'] = host_variables.get('group_names', [])
|
||||
inject['groups'] = self.inventory.groups_list()
|
||||
inject['vars'] = self.module_vars
|
||||
inject['defaults'] = self.default_vars
|
||||
inject['environment'] = self.environment
|
||||
|
||||
if self.inventory.basedir() is not None:
|
||||
|
|
Loading…
Reference in a new issue