mirror of https://github.com/ansible/ansible.git
Add toggle to fix module_defaults with module-as-redirected-action on a per-module basis (#77265)
* If there is a platform specific handler, prefer the resolved module over the resolved action when loading module_defaults Add a toggle for action plugins to prefer the resolved module when loading module_defaults Allow moving away from modules intercepted as actions pattern Fixes #77059pull/77906/head
parent
eecbaee7f4
commit
621e782ed0
@ -0,0 +1,55 @@
|
||||
minor_changes:
|
||||
- |
|
||||
Add an 'action_plugin' field for modules in runtime.yml plugin_routing.
|
||||
|
||||
This fixes module_defaults by supporting modules-as-redirected-actions
|
||||
without redirecting module_defaults entries to the common action.
|
||||
|
||||
.. code: yaml
|
||||
|
||||
plugin_routing:
|
||||
action:
|
||||
facts:
|
||||
redirect: ns.coll.eos
|
||||
command:
|
||||
redirect: ns.coll.eos
|
||||
modules:
|
||||
facts:
|
||||
redirect: ns.coll.eos_facts
|
||||
command:
|
||||
redirect: ns.coll.eos_command
|
||||
|
||||
With the runtime.yml above for ns.coll, a task such as
|
||||
|
||||
.. code: yaml
|
||||
|
||||
- hosts: all
|
||||
module_defaults:
|
||||
ns.coll.eos_facts: {'valid_for_eos_facts': 'value'}
|
||||
ns.coll.eos_command: {'not_valid_for_eos_facts': 'value'}
|
||||
tasks:
|
||||
- ns.coll.facts:
|
||||
|
||||
will end up with defaults for eos_facts and eos_command
|
||||
since both modules redirect to the same action.
|
||||
|
||||
To select an action plugin for a module without merging
|
||||
module_defaults, define an action_plugin field for the resolved
|
||||
module in the runtime.yml.
|
||||
|
||||
.. code: yaml
|
||||
|
||||
plugin_routing:
|
||||
modules:
|
||||
facts:
|
||||
redirect: ns.coll.eos_facts
|
||||
action_plugin: ns.coll.eos
|
||||
command:
|
||||
redirect: ns.coll.eos_command
|
||||
action_plugin: ns.coll.eos
|
||||
|
||||
The action_plugin field can be a redirected action plugin, as
|
||||
it is resolved normally.
|
||||
|
||||
Using the modified runtime.yml, the example task will only use
|
||||
the ns.coll.eos_facts defaults.
|
@ -0,0 +1,18 @@
|
||||
# Copyright: (c) 2022, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.plugins.action.normal import ActionModule as ActionBase
|
||||
from ansible.utils.vars import merge_hash
|
||||
|
||||
|
||||
class ActionModule(ActionBase):
|
||||
|
||||
def run(self, tmp=None, task_vars=None):
|
||||
|
||||
result = super(ActionModule, self).run(tmp, task_vars)
|
||||
result['action_plugin'] = 'eos'
|
||||
|
||||
return result
|
@ -0,0 +1,18 @@
|
||||
# Copyright: (c) 2022, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.plugins.action.normal import ActionModule as ActionBase
|
||||
from ansible.utils.vars import merge_hash
|
||||
|
||||
|
||||
class ActionModule(ActionBase):
|
||||
|
||||
def run(self, tmp=None, task_vars=None):
|
||||
|
||||
result = super(ActionModule, self).run(tmp, task_vars)
|
||||
result['action_plugin'] = 'ios'
|
||||
|
||||
return result
|
@ -0,0 +1,18 @@
|
||||
# Copyright: (c) 2022, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.plugins.action.normal import ActionModule as ActionBase
|
||||
from ansible.utils.vars import merge_hash
|
||||
|
||||
|
||||
class ActionModule(ActionBase):
|
||||
|
||||
def run(self, tmp=None, task_vars=None):
|
||||
|
||||
result = super(ActionModule, self).run(tmp, task_vars)
|
||||
result['action_plugin'] = 'vyos'
|
||||
|
||||
return result
|
@ -0,0 +1,35 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright: (c) 2022, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
DOCUMENTATION = r'''
|
||||
---
|
||||
module: eosfacts
|
||||
short_description: module to test module_defaults
|
||||
description: module to test module_defaults
|
||||
version_added: '2.13'
|
||||
'''
|
||||
|
||||
EXAMPLES = r'''
|
||||
'''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
eosfacts=dict(type=bool),
|
||||
),
|
||||
supports_check_mode=True
|
||||
)
|
||||
module.exit_json(eosfacts=module.params['eosfacts'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -0,0 +1,35 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright: (c) 2022, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
DOCUMENTATION = r'''
|
||||
---
|
||||
module: ios_facts
|
||||
short_description: module to test module_defaults
|
||||
description: module to test module_defaults
|
||||
version_added: '2.13'
|
||||
'''
|
||||
|
||||
EXAMPLES = r'''
|
||||
'''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
ios_facts=dict(type=bool),
|
||||
),
|
||||
supports_check_mode=True
|
||||
)
|
||||
module.exit_json(ios_facts=module.params['ios_facts'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -0,0 +1,35 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright: (c) 2022, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
DOCUMENTATION = r'''
|
||||
---
|
||||
module: module
|
||||
short_description: module to test module_defaults
|
||||
description: module to test module_defaults
|
||||
version_added: '2.13'
|
||||
'''
|
||||
|
||||
EXAMPLES = r'''
|
||||
'''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
action_option=dict(type=bool),
|
||||
),
|
||||
supports_check_mode=True
|
||||
)
|
||||
module.exit_json(action_option=module.params['action_option'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -0,0 +1,35 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright: (c) 2022, Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
DOCUMENTATION = r'''
|
||||
---
|
||||
module: vyosfacts
|
||||
short_description: module to test module_defaults
|
||||
description: module to test module_defaults
|
||||
version_added: '2.13'
|
||||
'''
|
||||
|
||||
EXAMPLES = r'''
|
||||
'''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
vyosfacts=dict(type=bool),
|
||||
),
|
||||
supports_check_mode=True
|
||||
)
|
||||
module.exit_json(vyosfacts=module.params['vyosfacts'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue