mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
Support for module param defaults (#22648)
This commit is contained in:
parent
f9bd29fe4d
commit
8673e1e661
4 changed files with 104 additions and 0 deletions
|
@ -521,6 +521,18 @@ class TaskExecutor:
|
|||
# get handler
|
||||
self._handler = self._get_action_handler(connection=self._connection, templar=templar)
|
||||
|
||||
# Apply default params for action/module, if present
|
||||
# These are collected as a list of dicts, so we need to merge them
|
||||
module_defaults = {}
|
||||
for default in self._task.module_defaults:
|
||||
module_defaults.update(default)
|
||||
if module_defaults:
|
||||
module_defaults = templar.template(module_defaults)
|
||||
if self._task.action in module_defaults:
|
||||
tmp_args = module_defaults[self._task.action].copy()
|
||||
tmp_args.update(self._task.args)
|
||||
self._task.args = tmp_args
|
||||
|
||||
# And filter out any fields which were set to default(omit), and got the omit token value
|
||||
omit_token = variables.get('omit')
|
||||
if omit_token is not None:
|
||||
|
|
|
@ -152,6 +152,9 @@ class Base(with_metaclass(BaseMeta, object)):
|
|||
# variables
|
||||
_vars = FieldAttribute(isa='dict', priority=100, inherit=False)
|
||||
|
||||
# module default params
|
||||
_module_defaults = FieldAttribute(isa='list', extend=True, prepend=True)
|
||||
|
||||
# flags and misc. settings
|
||||
_environment = FieldAttribute(isa='list', extend=True, prepend=True)
|
||||
_no_log = FieldAttribute(isa='bool')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue