From 69b2d7e0f3a981bc15cf2076fc01f89b07074b3f Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 22 May 2019 11:06:54 -0400 Subject: [PATCH] fix collection adjacent loading with --playbook-dir (#56194) * added inventory adjacent test --- changelogs/fragments/playbookdir_coll_adj_fix.yml | 2 ++ lib/ansible/cli/__init__.py | 8 +++++--- test/integration/targets/collections/runme.sh | 4 ++++ 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/playbookdir_coll_adj_fix.yml diff --git a/changelogs/fragments/playbookdir_coll_adj_fix.yml b/changelogs/fragments/playbookdir_coll_adj_fix.yml new file mode 100644 index 0000000000..88167dbfa6 --- /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 37fc2fee48..9f87c7e88d 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 4735875269..03415e1ac0 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 "$@"