diff options
author | Brian Coca <bcoca@users.noreply.github.com> | 2021-05-17 11:28:42 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-17 10:28:42 -0500 |
commit | 00d5a1610f37395dd9e6010b9f0dbb26342f3a59 (patch) | |
tree | a10baaeb84f69e8bc5101ced2f9175228421ffa4 | |
parent | 22adad0f1952822f3bccfdae28b0554fbb773583 (diff) | |
download | ansible-00d5a1610f37395dd9e6010b9f0dbb26342f3a59.tar.gz |
Fix pb subs collapse (#74301) (#74376)
* fix subdir parsing for plays
fixes #74283
Co-authored-by: Nikolaos Kakouros <nkak@kth.se>
(cherry picked from commit 6418f368e3d13c404cc2d53a6d5dab68f2809996)
6 files changed, 35 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 393ddbee7b..b398426583 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 |