mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-02 14:40:19 -07:00
fix module defaults (#56020)
* fix module defaults - corrected precedence (specific module > group) - made into reusable function - use from gather_facts/service/package to match 'actual module used'
This commit is contained in:
parent
8968d41599
commit
674a57c3fa
6 changed files with 45 additions and 15 deletions
|
@ -8,6 +8,7 @@ import os
|
|||
import time
|
||||
|
||||
from ansible import constants as C
|
||||
from ansible.executor.module_common import get_action_args_with_defaults
|
||||
from ansible.plugins.action import ActionBase
|
||||
from ansible.utils.vars import combine_vars
|
||||
|
||||
|
@ -39,6 +40,9 @@ class ActionModule(ActionBase):
|
|||
# This ensures we don't pass a ``None`` value as an argument expecting a specific type
|
||||
mod_args = dict((k, v) for k, v in mod_args.items() if v is not None)
|
||||
|
||||
# handle module defaults
|
||||
mod_args = get_action_args_with_defaults(fact_module, mod_args, self._task.module_defaults, self._templar)
|
||||
|
||||
return mod_args
|
||||
|
||||
def run(self, tmp=None, task_vars=None):
|
||||
|
|
|
@ -18,6 +18,7 @@ from __future__ import (absolute_import, division, print_function)
|
|||
__metaclass__ = type
|
||||
|
||||
from ansible.errors import AnsibleAction, AnsibleActionFail
|
||||
from ansible.executor.module_common import get_action_args_with_defaults
|
||||
from ansible.plugins.action import ActionBase
|
||||
from ansible.utils.display import Display
|
||||
|
||||
|
@ -64,6 +65,9 @@ class ActionModule(ActionBase):
|
|||
if 'use' in new_module_args:
|
||||
del new_module_args['use']
|
||||
|
||||
# get defaults for specific module
|
||||
new_module_args = get_action_args_with_defaults(module, new_module_args, self._task.module_defaults, self._templar)
|
||||
|
||||
display.vvvv("Running %s" % module)
|
||||
result.update(self._execute_module(module_name=module, module_args=new_module_args, task_vars=task_vars, wrap_async=self._task.async_val))
|
||||
else:
|
||||
|
|
|
@ -19,6 +19,7 @@ __metaclass__ = type
|
|||
|
||||
|
||||
from ansible.errors import AnsibleAction, AnsibleActionFail
|
||||
from ansible.executor.module_common import get_action_args_with_defaults
|
||||
from ansible.plugins.action import ActionBase
|
||||
|
||||
|
||||
|
@ -71,6 +72,9 @@ class ActionModule(ActionBase):
|
|||
del new_module_args[unused]
|
||||
self._display.warning('Ignoring "%s" as it is not used in "%s"' % (unused, module))
|
||||
|
||||
# get defaults for specific module
|
||||
new_module_args = get_action_args_with_defaults(module, new_module_args, self._task.module_defaults, self._templar)
|
||||
|
||||
self._display.vvvv("Running %s" % module)
|
||||
result.update(self._execute_module(module_name=module, module_args=new_module_args, task_vars=task_vars, wrap_async=self._task.async_val))
|
||||
else:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue