diff --git a/changelogs/fragments/collection-ad-hoc.yml b/changelogs/fragments/collection-ad-hoc.yml new file mode 100644 index 00000000000..f9355527dd7 --- /dev/null +++ b/changelogs/fragments/collection-ad-hoc.yml @@ -0,0 +1,2 @@ +minor_changes: +- Add path of collection location in Ansible CLI version info. diff --git a/lib/ansible/cli/arguments/option_helpers.py b/lib/ansible/cli/arguments/option_helpers.py index e18cd6ce9ae..021fcb872e6 100644 --- a/lib/ansible/cli/arguments/option_helpers.py +++ b/lib/ansible/cli/arguments/option_helpers.py @@ -178,6 +178,7 @@ def version(prog=None): cpath = C.DEFAULT_MODULE_PATH result = result + "\n configured module search path = %s" % cpath result = result + "\n ansible python module location = %s" % ':'.join(ansible.__path__) + result = result + "\n ansible collection location = %s" % ':'.join(C.COLLECTIONS_PATHS) result = result + "\n executable location = %s" % sys.argv[0] result = result + "\n python version = %s" % ''.join(sys.version.splitlines()) return result diff --git a/test/integration/targets/ansible/ansible-testé.cfg b/test/integration/targets/ansible/ansible-testé.cfg index 61a99f48bbd..09af947fdb3 100644 --- a/test/integration/targets/ansible/ansible-testé.cfg +++ b/test/integration/targets/ansible/ansible-testé.cfg @@ -1,2 +1,3 @@ [defaults] remote_user = admin +collections_paths = /tmp/collections diff --git a/test/integration/targets/ansible/runme.sh b/test/integration/targets/ansible/runme.sh index 23ae18632d7..66951823a36 100755 --- a/test/integration/targets/ansible/runme.sh +++ b/test/integration/targets/ansible/runme.sh @@ -13,6 +13,12 @@ ansible-config dump -c ./ansible-testé.cfg | grep 'DEFAULT_REMOTE_USER([^)]*) = ANSIBLE_REMOTE_USER=administrator ansible-config dump| grep 'DEFAULT_REMOTE_USER([^)]*) = administrator\>' ansible-config list | grep 'DEFAULT_REMOTE_USER' +# Collection +ansible-config view -c ./ansible-testé.cfg | grep 'collections_paths = /tmp/collections' +ansible-config dump -c ./ansible-testé.cfg | grep 'COLLECTIONS_PATHS([^)]*) =' +ANSIBLE_COLLECTIONS_PATHS=/tmp/collections ansible-config dump| grep 'COLLECTIONS_PATHS([^)]*) =' +ansible-config list | grep 'COLLECTIONS_PATHS' + # 'view' command must fail when config file is missing or has an invalid file extension ansible-config view -c ./ansible-non-existent.cfg 2> err1.txt || grep -Eq 'ERROR! The provided configuration file is missing or not accessible:' err1.txt || (cat err*.txt; rm -f err1.txt; exit 1) ansible-config view -c ./no-extension 2> err2.txt || grep -q 'Unsupported configuration file extension' err2.txt || (cat err2.txt; rm -f err*.txt; exit 1) diff --git a/test/units/cli/arguments/test_optparse_helpers.py b/test/units/cli/arguments/test_optparse_helpers.py index 0e80fba9965..894f3bf8c81 100644 --- a/test/units/cli/arguments/test_optparse_helpers.py +++ b/test/units/cli/arguments/test_optparse_helpers.py @@ -29,6 +29,7 @@ VERSION_OUTPUT = opt_help.version(prog=FAKE_PROG) u'config file = %s' % C.CONFIG_FILE, u'configured module search path = %s' % cpath, u'ansible python module location = %s' % ':'.join(ansible_path), + u'ansible collection location = %s' % ':'.join(C.COLLECTIONS_PATHS), u'executable location = ', u'python version = %s' % ''.join(sys.version.splitlines()), ] diff --git a/test/units/cli/test_adhoc.py b/test/units/cli/test_adhoc.py index 0e7475c603a..b660993bff1 100644 --- a/test/units/cli/test_adhoc.py +++ b/test/units/cli/test_adhoc.py @@ -104,10 +104,11 @@ def test_ansible_version(capsys, mocker): # Python 2.6 does return a named tuple, so get the first item version_lines = version[0].splitlines() - assert len(version_lines) == 6, 'Incorrect number of lines in "ansible --version" output' + assert len(version_lines) == 7, 'Incorrect number of lines in "ansible --version" output' assert re.match('ansible [0-9.a-z]+$', version_lines[0]), 'Incorrect ansible version line in "ansible --version" output' assert re.match(' config file = .*$', version_lines[1]), 'Incorrect config file line in "ansible --version" output' assert re.match(' configured module search path = .*$', version_lines[2]), 'Incorrect module search path in "ansible --version" output' assert re.match(' ansible python module location = .*$', version_lines[3]), 'Incorrect python module location in "ansible --version" output' - assert re.match(' executable location = .*$', version_lines[4]), 'Incorrect executable locaction in "ansible --version" output' - assert re.match(' python version = .*$', version_lines[5]), 'Incorrect python version in "ansible --version" output' + assert re.match(' ansible collection location = .*$', version_lines[4]), 'Incorrect collection location in "ansible --version" output' + assert re.match(' executable location = .*$', version_lines[5]), 'Incorrect executable locaction in "ansible --version" output' + assert re.match(' python version = .*$', version_lines[6]), 'Incorrect python version in "ansible --version" output' diff --git a/test/units/cli/test_cli.py b/test/units/cli/test_cli.py index 6dcd9e35b19..09445a2573f 100644 --- a/test/units/cli/test_cli.py +++ b/test/units/cli/test_cli.py @@ -61,7 +61,7 @@ class TestCliBuildVaultIds(unittest.TestCase): self.assertEqual(res, []) def test_no_vault_id_no_auto_prompt(self): - # similate 'ansible-playbook site.yml' with out --ask-vault-pass, should not prompt + # simulate 'ansible-playbook site.yml' with out --ask-vault-pass, should not prompt res = cli.CLI.build_vault_ids([], auto_prompt=False) self.assertEqual(res, [])