mirror of https://github.com/ansible/ansible.git
Add a resolved_action task attribute (#74709)
* The resolved_action is the formatted version of the final plugin in the PluginLoadContext's redirect_list * Collection plugins are represented as FQCN * Legacy plugins are represented with only the plugin name * Add tests * Changelogpull/75078/head
parent
a4021977ad
commit
865bda3a11
@ -0,0 +1,2 @@
|
||||
minor_changes:
|
||||
- Task - Add a resolved_action attribute for Task objects to get the final resolved plugin.
|
@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eux
|
||||
|
||||
export ANSIBLE_CALLBACKS_ENABLED=display_resolved_action
|
||||
|
||||
ansible-playbook test_task_resolved_plugin/unqualified.yml "$@" | tee out.txt
|
||||
action_resolution=(
|
||||
"legacy_action == legacy_action"
|
||||
"legacy_module == legacy_module"
|
||||
"debug == ansible.builtin.debug"
|
||||
"ping == ansible.builtin.ping"
|
||||
)
|
||||
for result in "${action_resolution[@]}"; do
|
||||
grep -q out.txt -e "$result"
|
||||
done
|
||||
|
||||
ansible-playbook test_task_resolved_plugin/unqualified_and_collections_kw.yml "$@" | tee out.txt
|
||||
action_resolution=(
|
||||
"legacy_action == legacy_action"
|
||||
"legacy_module == legacy_module"
|
||||
"debug == ansible.builtin.debug"
|
||||
"ping == ansible.builtin.ping"
|
||||
"collection_action == test_ns.test_coll.collection_action"
|
||||
"collection_module == test_ns.test_coll.collection_module"
|
||||
"formerly_action == test_ns.test_coll.collection_action"
|
||||
"formerly_module == test_ns.test_coll.collection_module"
|
||||
)
|
||||
for result in "${action_resolution[@]}"; do
|
||||
grep -q out.txt -e "$result"
|
||||
done
|
||||
|
||||
ansible-playbook test_task_resolved_plugin/fqcn.yml "$@" | tee out.txt
|
||||
action_resolution=(
|
||||
"ansible.legacy.legacy_action == legacy_action"
|
||||
"ansible.legacy.legacy_module == legacy_module"
|
||||
"ansible.legacy.debug == ansible.builtin.debug"
|
||||
"ansible.legacy.ping == ansible.builtin.ping"
|
||||
"ansible.builtin.debug == ansible.builtin.debug"
|
||||
"ansible.builtin.ping == ansible.builtin.ping"
|
||||
"test_ns.test_coll.collection_action == test_ns.test_coll.collection_action"
|
||||
"test_ns.test_coll.collection_module == test_ns.test_coll.collection_module"
|
||||
"test_ns.test_coll.formerly_action == test_ns.test_coll.collection_action"
|
||||
"test_ns.test_coll.formerly_module == test_ns.test_coll.collection_module"
|
||||
)
|
||||
for result in "${action_resolution[@]}"; do
|
||||
grep -q out.txt -e "$result"
|
||||
done
|
@ -0,0 +1,14 @@
|
||||
# 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 import ActionBase
|
||||
|
||||
|
||||
class ActionModule(ActionBase):
|
||||
TRANSFERS_FILES = False
|
||||
_VALID_ARGS = frozenset()
|
||||
|
||||
def run(self, tmp=None, task_vars=None):
|
||||
return {'changed': False}
|
@ -0,0 +1,37 @@
|
||||
# (c) 2020 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 = '''
|
||||
name: display_resolved_action
|
||||
type: aggregate
|
||||
short_description: Displays the requested and resolved actions at the end of a playbook.
|
||||
description:
|
||||
- Displays the requested and resolved actions in the format "requested == resolved".
|
||||
requirements:
|
||||
- Enable in configuration.
|
||||
'''
|
||||
|
||||
from ansible import constants as C
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
|
||||
|
||||
class CallbackModule(CallbackBase):
|
||||
|
||||
CALLBACK_VERSION = 2.0
|
||||
CALLBACK_TYPE = 'aggregate'
|
||||
CALLBACK_NAME = 'display_resolved_action'
|
||||
CALLBACK_NEEDS_ENABLED = True
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(CallbackModule, self).__init__(*args, **kwargs)
|
||||
self.requested_to_resolved = {}
|
||||
|
||||
def v2_playbook_on_task_start(self, task, is_conditional):
|
||||
self.requested_to_resolved[task.action] = task.resolved_action
|
||||
|
||||
def v2_playbook_on_stats(self, stats):
|
||||
for requested, resolved in self.requested_to_resolved.items():
|
||||
self._display.display("%s == %s" % (requested, resolved), screen_only=True)
|
@ -0,0 +1,7 @@
|
||||
plugin_routing:
|
||||
modules:
|
||||
formerly_module:
|
||||
redirect: test_ns.test_coll.collection_module
|
||||
action:
|
||||
formerly_action:
|
||||
redirect: test_ns.test_coll.collection_action
|
@ -0,0 +1,14 @@
|
||||
# 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 import ActionBase
|
||||
|
||||
|
||||
class ActionModule(ActionBase):
|
||||
TRANSFERS_FILES = False
|
||||
_VALID_ARGS = frozenset()
|
||||
|
||||
def run(self, tmp=None, task_vars=None):
|
||||
return {'changed': False}
|
@ -0,0 +1,29 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# 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 = '''
|
||||
---
|
||||
module: collection_module
|
||||
short_description: A module to test a task's resolved action name.
|
||||
description: A module to test a task's resolved action name.
|
||||
options: {}
|
||||
author: Ansible Core Team
|
||||
notes:
|
||||
- Supports C(check_mode).
|
||||
'''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(supports_check_mode=True, argument_spec={})
|
||||
module.exit_json(changed=False)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -0,0 +1,14 @@
|
||||
---
|
||||
- hosts: localhost
|
||||
gather_facts: no
|
||||
tasks:
|
||||
- ansible.legacy.legacy_action:
|
||||
- ansible.legacy.legacy_module:
|
||||
- ansible.legacy.debug:
|
||||
- ansible.legacy.ping:
|
||||
- ansible.builtin.debug:
|
||||
- ansible.builtin.ping:
|
||||
- test_ns.test_coll.collection_action:
|
||||
- test_ns.test_coll.collection_module:
|
||||
- test_ns.test_coll.formerly_action:
|
||||
- test_ns.test_coll.formerly_module:
|
@ -0,0 +1,29 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# 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 = '''
|
||||
---
|
||||
module: legacy_module
|
||||
short_description: A module to test a task's resolved action name.
|
||||
description: A module to test a task's resolved action name.
|
||||
options: {}
|
||||
author: Ansible Core Team
|
||||
notes:
|
||||
- Supports C(check_mode).
|
||||
'''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(supports_check_mode=True, argument_spec={})
|
||||
module.exit_json(changed=False)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -0,0 +1,8 @@
|
||||
---
|
||||
- hosts: localhost
|
||||
gather_facts: no
|
||||
tasks:
|
||||
- legacy_action:
|
||||
- legacy_module:
|
||||
- debug:
|
||||
- ping:
|
@ -0,0 +1,14 @@
|
||||
---
|
||||
- hosts: localhost
|
||||
gather_facts: no
|
||||
collections:
|
||||
- test_ns.test_coll
|
||||
tasks:
|
||||
- legacy_action:
|
||||
- legacy_module:
|
||||
- debug:
|
||||
- ping:
|
||||
- collection_action:
|
||||
- collection_module:
|
||||
- formerly_action:
|
||||
- formerly_module:
|
Loading…
Reference in New Issue