diff --git a/changelogs/fragments/playbookdir_coll_adj_fix.yml b/changelogs/fragments/playbookdir_coll_adj_fix.yml new file mode 100644 index 00000000000..88167dbfa6b --- /dev/null +++ b/changelogs/fragments/playbookdir_coll_adj_fix.yml @@ -0,0 +1,2 @@ +bugfixes: + - Add missing directory provided via ``--playbook-dir`` to adjacent collection loading diff --git a/lib/ansible/cli/__init__.py b/lib/ansible/cli/__init__.py index 37fc2fee483..9f87c7e88da 100644 --- a/lib/ansible/cli/__init__.py +++ b/lib/ansible/cli/__init__.py @@ -15,20 +15,21 @@ import sys from abc import ABCMeta, abstractmethod +from ansible.cli.arguments import option_helpers as opt_help from ansible import constants as C from ansible import context -from ansible.cli.arguments import option_helpers as opt_help from ansible.errors import AnsibleError from ansible.inventory.manager import InventoryManager from ansible.module_utils.six import with_metaclass, string_types from ansible.module_utils._text import to_bytes, to_text from ansible.parsing.dataloader import DataLoader +from ansible.parsing.vault import PromptVaultSecret, get_file_vault_secret +from ansible.plugins.loader import add_all_plugin_dirs from ansible.release import __version__ +from ansible.utils.collection_loader import set_collection_playbook_paths from ansible.utils.display import Display from ansible.utils.path import unfrackpath from ansible.vars.manager import VariableManager -from ansible.parsing.vault import PromptVaultSecret, get_file_vault_secret -from ansible.plugins.loader import add_all_plugin_dirs try: import argcomplete @@ -433,6 +434,7 @@ class CLI(with_metaclass(ABCMeta, object)): if basedir: loader.set_basedir(basedir) add_all_plugin_dirs(basedir) + set_collection_playbook_paths(basedir) vault_ids = list(options['vault_ids']) default_vault_ids = C.DEFAULT_VAULT_IDENTITY_LIST diff --git a/test/integration/targets/collections/runme.sh b/test/integration/targets/collections/runme.sh index 47358752690..03415e1ac0b 100755 --- a/test/integration/targets/collections/runme.sh +++ b/test/integration/targets/collections/runme.sh @@ -32,3 +32,7 @@ fi # run test playbook ansible-playbook -i "${INVENTORY_PATH}" -i ./a.statichost.yml -v "${TEST_PLAYBOOK}" + +# test adjacent with --playbook-dir +export ANSIBLE_COLLECTIONS_PATHS='' +ANSIBLE_INVENTORY_ANY_UNPARSED_IS_FAILED=1 ansible-inventory -i a.statichost.yml --list --export --playbook-dir=. -v "$@"