diff options
7 files changed, 41 insertions, 0 deletions
diff --git a/changelogs/fragments/coll_pb_subdir_fixes.yml b/changelogs/fragments/coll_pb_subdir_fixes.yml new file mode 100644 index 0000000000..507c6f10e8 --- /dev/null +++ b/changelogs/fragments/coll_pb_subdir_fixes.yml @@ -0,0 +1,2 @@ +bugfixes: + - playbook loaded from collection subdir now does not ignore subdirs. diff --git a/lib/ansible/utils/collection_loader/_collection_finder.py b/lib/ansible/utils/collection_loader/_collection_finder.py index f684da2ef0..e0c3c109b9 100644 --- a/lib/ansible/utils/collection_loader/_collection_finder.py +++ b/lib/ansible/utils/collection_loader/_collection_finder.py @@ -891,6 +891,12 @@ def _get_collection_playbook_path(playbook): if pkg: cpath = os.path.join(sys.modules[acr.n_python_collection_package_name].__file__.replace('__synthetic__', 'playbooks')) + + if acr.subdirs: + paths = [to_native(x) for x in acr.subdirs.split(u'.')] + paths.insert(0, cpath) + cpath = os.path.join(*paths) + path = os.path.join(cpath, to_native(acr.resource)) if os.path.exists(to_bytes(path)): return acr.resource, path, acr.collection diff --git a/test/integration/targets/collections/collection_root_user/ansible_collections/testns/testcoll/playbooks/play.yml b/test/integration/targets/collections/collection_root_user/ansible_collections/testns/testcoll/playbooks/play.yml new file mode 100644 index 0000000000..6be246cc51 --- /dev/null +++ b/test/integration/targets/collections/collection_root_user/ansible_collections/testns/testcoll/playbooks/play.yml @@ -0,0 +1,4 @@ +- hosts: localhost + gather_facts: false + tasks: + - set_fact: play='tldr' diff --git a/test/integration/targets/collections/collection_root_user/ansible_collections/testns/testcoll/playbooks/type/play.yml b/test/integration/targets/collections/collection_root_user/ansible_collections/testns/testcoll/playbooks/type/play.yml new file mode 100644 index 0000000000..dd6d563fec --- /dev/null +++ b/test/integration/targets/collections/collection_root_user/ansible_collections/testns/testcoll/playbooks/type/play.yml @@ -0,0 +1,4 @@ +- hosts: localhost + gather_facts: false + tasks: + - set_fact: play_type='in type subdir' diff --git a/test/integration/targets/collections/collection_root_user/ansible_collections/testns/testcoll/playbooks/type/subtype/play.yml b/test/integration/targets/collections/collection_root_user/ansible_collections/testns/testcoll/playbooks/type/subtype/play.yml new file mode 100644 index 0000000000..0e33a761a5 --- /dev/null +++ b/test/integration/targets/collections/collection_root_user/ansible_collections/testns/testcoll/playbooks/type/subtype/play.yml @@ -0,0 +1,4 @@ +- hosts: localhost + gather_facts: false + tasks: + - set_fact: play_type_subtype='in subtype subdir' diff --git a/test/integration/targets/collections/import_collection_pb.yml b/test/integration/targets/collections/import_collection_pb.yml index 47bfef13d4..511d948664 100644 --- a/test/integration/targets/collections/import_collection_pb.yml +++ b/test/integration/targets/collections/import_collection_pb.yml @@ -1,2 +1,17 @@ - import_playbook: testns.testcoll.default_collection_playbook.yml - import_playbook: testns.testcoll.default_collection_playbook + +# test subdirs +- import_playbook: "testns.testcoll.play" +- import_playbook: "testns.testcoll.type.play" +- import_playbook: "testns.testcoll.type.subtype.play" + +- hosts: localhost + gather_facts: false + tasks: + - name: check values from imports + assert: + that: + - play is defined + - play_type is defined + - play_type_subtype is defined diff --git a/test/lib/ansible_test/_data/legacy_collection_loader/_collection_finder.py b/test/lib/ansible_test/_data/legacy_collection_loader/_collection_finder.py index f684da2ef0..e0c3c109b9 100644 --- a/test/lib/ansible_test/_data/legacy_collection_loader/_collection_finder.py +++ b/test/lib/ansible_test/_data/legacy_collection_loader/_collection_finder.py @@ -891,6 +891,12 @@ def _get_collection_playbook_path(playbook): if pkg: cpath = os.path.join(sys.modules[acr.n_python_collection_package_name].__file__.replace('__synthetic__', 'playbooks')) + + if acr.subdirs: + paths = [to_native(x) for x in acr.subdirs.split(u'.')] + paths.insert(0, cpath) + cpath = os.path.join(*paths) + path = os.path.join(cpath, to_native(acr.resource)) if os.path.exists(to_bytes(path)): return acr.resource, path, acr.collection |