diff --git a/changelogs/fragments/59548-import-playbook-plugin-dirs.yml b/changelogs/fragments/59548-import-playbook-plugin-dirs.yml new file mode 100644 index 00000000000..6c6922f0e0e --- /dev/null +++ b/changelogs/fragments/59548-import-playbook-plugin-dirs.yml @@ -0,0 +1,4 @@ +bugfixes: +- plugin loader - Move plugin loader playbook dir additions back to ``Playbook`` instead of ``PlaybookCLI`` + to solve sub directory playbook relative plugins to be located + (https://github.com/ansible/ansible/issues/59548) diff --git a/lib/ansible/playbook/__init__.py b/lib/ansible/playbook/__init__.py index 74257c061bb..17b5f2fe76f 100644 --- a/lib/ansible/playbook/__init__.py +++ b/lib/ansible/playbook/__init__.py @@ -26,6 +26,7 @@ from ansible.errors import AnsibleParserError from ansible.module_utils._text import to_text, to_native from ansible.playbook.play import Play from ansible.playbook.playbook_include import PlaybookInclude +from ansible.plugins.loader import add_all_plugin_dirs from ansible.utils.display import Display display = Display() @@ -61,6 +62,8 @@ class Playbook: cur_basedir = self._loader.get_basedir() self._loader.set_basedir(self._basedir) + add_all_plugin_dirs(self._basedir) + self._file_name = file_name try: diff --git a/test/integration/targets/include_import/playbook/sub_playbook/library/helloworld.py b/test/integration/targets/include_import/playbook/sub_playbook/library/helloworld.py new file mode 100644 index 00000000000..bc0907677ef --- /dev/null +++ b/test/integration/targets/include_import/playbook/sub_playbook/library/helloworld.py @@ -0,0 +1,27 @@ +#!/usr/bin/python +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +from ansible.module_utils.basic import AnsibleModule + + +def main(): + module = AnsibleModule(argument_spec={}) + + module.exit_json(msg='Hello, World!') + + +if __name__ == '__main__': + main() diff --git a/test/integration/targets/include_import/playbook/sub_playbook/sub_playbook.yml b/test/integration/targets/include_import/playbook/sub_playbook/sub_playbook.yml new file mode 100644 index 00000000000..4399d935ae2 --- /dev/null +++ b/test/integration/targets/include_import/playbook/sub_playbook/sub_playbook.yml @@ -0,0 +1,4 @@ +- hosts: localhost + gather_facts: false + tasks: + - helloworld: diff --git a/test/integration/targets/include_import/playbook/test_import_playbook.yml b/test/integration/targets/include_import/playbook/test_import_playbook.yml index ec6e77f10e5..91c6a198801 100644 --- a/test/integration/targets/include_import/playbook/test_import_playbook.yml +++ b/test/integration/targets/include_import/playbook/test_import_playbook.yml @@ -18,3 +18,6 @@ - import_playbook: playbook_needing_vars.yml vars: import_playbook_role_name: import_playbook_role + +# https://github.com/ansible/ansible/issues/59548 +- import_playbook: sub_playbook/sub_playbook.yml