diff options
3 files changed, 16 insertions, 2 deletions
diff --git a/changelogs/fragments/76164-alias-action-groups-shortnames.yml b/changelogs/fragments/76164-alias-action-groups-shortnames.yml new file mode 100644 index 0000000000..155ec441bb --- /dev/null +++ b/changelogs/fragments/76164-alias-action-groups-shortnames.yml @@ -0,0 +1,4 @@ +bugfixes: +- > + ``action_groups`` - Alias short names in collection action groups to FQCR of the owning collection + (https://github.com/ansible/ansible/issues/76164) diff --git a/lib/ansible/executor/module_common.py b/lib/ansible/executor/module_common.py index ade9179c94..8c48f72bc4 100644 --- a/lib/ansible/executor/module_common.py +++ b/lib/ansible/executor/module_common.py @@ -40,7 +40,7 @@ from ansible.executor.powershell import module_manifest as ps_manifest from ansible.module_utils.common.json import AnsibleJSONEncoder from ansible.module_utils.common.text.converters import to_bytes, to_text, to_native from ansible.plugins.loader import module_utils_loader -from ansible.utils.collection_loader._collection_finder import _get_collection_metadata, _nested_dict_get +from ansible.utils.collection_loader._collection_finder import AnsibleCollectionRef, _get_collection_metadata, _nested_dict_get # Must import strategy and use write_locks from there # If we import write_locks directly then we end up binding a @@ -1433,6 +1433,16 @@ def get_action_args_with_defaults(action, args, defaults, templar, redirected_na except ValueError: # The collection may not be installed continue + else: + for name, groups in list(action_group.items()): + if AnsibleCollectionRef.is_valid_fqcr(name): + continue + # Only alias short names to an FQCR from the owning collection + fqcr = '{0}.{1}'.format(collection_name, name) + if fqcr in action_group: + # Don't overwrite + continue + action_group[fqcr] = groups if any(name for name in redirected_names if name in action_group): tmp_args.update((module_defaults.get('group/%s' % group_name) or {}).copy()) diff --git a/test/integration/targets/module_defaults/collections/ansible_collections/testns/testcoll/meta/runtime.yml b/test/integration/targets/module_defaults/collections/ansible_collections/testns/testcoll/meta/runtime.yml index 62695fbc95..6ff9dbfb37 100644 --- a/test/integration/targets/module_defaults/collections/ansible_collections/testns/testcoll/meta/runtime.yml +++ b/test/integration/targets/module_defaults/collections/ansible_collections/testns/testcoll/meta/runtime.yml @@ -1,6 +1,6 @@ action_groups: testgroup: - - testns.testcoll.echo1 + - echo1 - testns.testcoll.echo2 # note we can define defaults for an action - testns.testcoll.echoaction |