summaryrefslogtreecommitdiff
path: root/lib/ansible
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ansible')
-rw-r--r--lib/ansible/parsing/mod_args.py10
-rw-r--r--lib/ansible/playbook/task.py5
-rw-r--r--lib/ansible/plugins/loader.py16
3 files changed, 30 insertions, 1 deletions
diff --git a/lib/ansible/parsing/mod_args.py b/lib/ansible/parsing/mod_args.py
index 96e6b8570f..595580cecf 100644
--- a/lib/ansible/parsing/mod_args.py
+++ b/lib/ansible/parsing/mod_args.py
@@ -26,6 +26,7 @@ from ansible.module_utils._text import to_text
from ansible.parsing.splitter import parse_kv, split_args
from ansible.plugins.loader import module_loader, action_loader
from ansible.template import Templar
+from ansible.utils.collection_loader import AnsibleCollectionRef
from ansible.utils.fqcn import add_internal_fqcns
from ansible.utils.sentinel import Sentinel
@@ -120,6 +121,7 @@ class ModuleArgsParser:
self._task_attrs.update(['local_action', 'static'])
self._task_attrs = frozenset(self._task_attrs)
+ self.resolved_action = None
self.internal_redirect_list = []
def _split_module_string(self, module_string):
@@ -299,6 +301,7 @@ class ModuleArgsParser:
# walk the filtered input dictionary to see if we recognize a module name
for item, value in iteritems(non_task_ds):
+ context = None
is_action_candidate = False
if item in BUILTIN_TASKS:
is_action_candidate = True
@@ -306,6 +309,7 @@ class ModuleArgsParser:
is_action_candidate = True
else:
# If the plugin is resolved and redirected smuggle the list of candidate names via the task attribute 'internal_redirect_list'
+ # TODO: remove self.internal_redirect_list (and Task._ansible_internal_redirect_list) once TE can use the resolved name for module_defaults
context = action_loader.find_plugin_with_context(item, collection_list=self._collection_list)
if not context.resolved:
context = module_loader.find_plugin_with_context(item, collection_list=self._collection_list)
@@ -314,12 +318,16 @@ class ModuleArgsParser:
elif context.redirect_list:
self.internal_redirect_list = context.redirect_list
- is_action_candidate = bool(self.internal_redirect_list)
+ is_action_candidate = context.resolved and bool(context.redirect_list)
if is_action_candidate:
# finding more than one module name is a problem
if action is not None:
raise AnsibleParserError("conflicting action statements: %s, %s" % (action, item), obj=self._task_ds)
+
+ if context is not None and context.resolved:
+ self.resolved_action = context.resolved_fqcn
+
action = item
thing = value
action, args = self._normalize_parameters(thing, action=action, additional_args=additional_args)
diff --git a/lib/ansible/playbook/task.py b/lib/ansible/playbook/task.py
index b92bd1971b..84c735d6b4 100644
--- a/lib/ansible/playbook/task.py
+++ b/lib/ansible/playbook/task.py
@@ -98,6 +98,7 @@ class Task(Base, Conditional, Taggable, CollectionSearch):
self._role = role
self._parent = None
self.implicit = False
+ self.resolved_action = None
if task_include:
self._parent = task_include
@@ -227,6 +228,7 @@ class Task(Base, Conditional, Taggable, CollectionSearch):
raise AnsibleParserError(to_native(e), obj=ds, orig_exc=e)
else:
self._ansible_internal_redirect_list = args_parser.internal_redirect_list[:]
+ self.resolved_action = args_parser.resolved_action
# the command/shell/script modules used to support the `cmd` arg,
# which corresponds to what we now call _raw_params, so move that
@@ -403,6 +405,7 @@ class Task(Base, Conditional, Taggable, CollectionSearch):
new_me._role = self._role
new_me.implicit = self.implicit
+ new_me.resolved_action = self.resolved_action
return new_me
@@ -421,6 +424,7 @@ class Task(Base, Conditional, Taggable, CollectionSearch):
data['_ansible_internal_redirect_list'] = self._ansible_internal_redirect_list[:]
data['implicit'] = self.implicit
+ data['resolved_action'] = self.resolved_action
return data
@@ -453,6 +457,7 @@ class Task(Base, Conditional, Taggable, CollectionSearch):
self._ansible_internal_redirect_list = data.get('_ansible_internal_redirect_list', [])
self.implicit = data.get('implicit', False)
+ self.resolved_action = data.get('resolved_action')
super(Task, self).deserialize(data)
diff --git a/lib/ansible/plugins/loader.py b/lib/ansible/plugins/loader.py
index cbd2fd382e..a80aae7c2b 100644
--- a/lib/ansible/plugins/loader.py
+++ b/lib/ansible/plugins/loader.py
@@ -129,6 +129,22 @@ class PluginLoadContext(object):
self.removal_version = None
self.deprecation_warnings = []
self.resolved = False
+ self._resolved_fqcn = None
+
+ @property
+ def resolved_fqcn(self):
+ if not self.resolved:
+ return
+
+ if not self._resolved_fqcn:
+ final_plugin = self.redirect_list[-1]
+ if AnsibleCollectionRef.is_valid_fqcr(final_plugin) and final_plugin.startswith('ansible.legacy.'):
+ final_plugin = final_plugin.split('ansible.legacy.')[-1]
+ if self.plugin_resolved_collection and not AnsibleCollectionRef.is_valid_fqcr(final_plugin):
+ final_plugin = self.plugin_resolved_collection + '.' + final_plugin
+ self._resolved_fqcn = final_plugin
+
+ return self._resolved_fqcn
def record_deprecation(self, name, deprecation, collection_name):
if not deprecation: