From 66f089de4bbb851a6db18ef53c89ee8f58b83242 Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Fri, 10 Jan 2020 05:24:36 +1000 Subject: [PATCH] ansible-galaxy ignore empty server_list (#65986) * ansible-galaxy ignore empty server_list (cherry picked from commit aba8f12495376557f23ef412a72cb932441bb454) --- changelogs/fragments/galaxy-server-list.yaml | 2 ++ lib/ansible/cli/galaxy.py | 5 ++++- .../targets/ansible-galaxy/runme.sh | 21 ++++++++++++++++--- 3 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/galaxy-server-list.yaml diff --git a/changelogs/fragments/galaxy-server-list.yaml b/changelogs/fragments/galaxy-server-list.yaml new file mode 100644 index 00000000000..93460fc823e --- /dev/null +++ b/changelogs/fragments/galaxy-server-list.yaml @@ -0,0 +1,2 @@ +bugfixes: +- ansible-galaxy - Treat the ``GALAXY_SERVER_LIST`` config entry that is defined but with no values as an empty list diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py index 72c038f49c9..4150f6cb4d7 100644 --- a/lib/ansible/cli/galaxy.py +++ b/lib/ansible/cli/galaxy.py @@ -320,7 +320,10 @@ class GalaxyCLI(CLI): ('auth_url', False)] config_servers = [] - for server_key in (C.GALAXY_SERVER_LIST or []): + + # Need to filter out empty strings or non truthy values as an empty server list env var is equal to ['']. + server_list = [s for s in C.GALAXY_SERVER_LIST or [] if s] + for server_key in server_list: # Config definitions are looked up dynamically based on the C.GALAXY_SERVER_LIST entry. We look up the # section [galaxy_server.] for the values url, username, password, and token. config_dict = dict((k, server_config_def(server_key, k, req)) for k, req in server_def) diff --git a/test/integration/targets/ansible-galaxy/runme.sh b/test/integration/targets/ansible-galaxy/runme.sh index 1082bd22f40..f815eccc2a0 100755 --- a/test/integration/targets/ansible-galaxy/runme.sh +++ b/test/integration/targets/ansible-galaxy/runme.sh @@ -171,7 +171,7 @@ pushd "${galaxy_testdir}" f_ansible_galaxy_status \ "collection install from local tarball test" - ansible-galaxy collection install "ansible_test-my_collection-1.0.0.tar.gz" -p ./install | tee out.txt + ansible-galaxy collection install "ansible_test-my_collection-1.0.0.tar.gz" -p ./install "$@" | tee out.txt [[ -f "${galaxy_testdir}/install/ansible_collections/ansible_test/my_collection/MANIFEST.json" ]] grep "Installing 'ansible_test.my_collection:1.0.0' to .*" out.txt @@ -180,7 +180,7 @@ f_ansible_galaxy_status \ f_ansible_galaxy_status \ "collection install with existing collection and without --force" - ansible-galaxy collection install "ansible_test-my_collection-1.0.0.tar.gz" -p ./install | tee out.txt + ansible-galaxy collection install "ansible_test-my_collection-1.0.0.tar.gz" -p ./install "$@" | tee out.txt [[ -f "${galaxy_testdir}/install/ansible_collections/ansible_test/my_collection/MANIFEST.json" ]] grep "Skipping 'ansible_test.my_collection' as it is already installed" out.txt @@ -188,7 +188,22 @@ f_ansible_galaxy_status \ f_ansible_galaxy_status \ "collection install with existing collection and with --force" - ansible-galaxy collection install "ansible_test-my_collection-1.0.0.tar.gz" -p ./install --force | tee out.txt + ansible-galaxy collection install "ansible_test-my_collection-1.0.0.tar.gz" -p ./install --force "$@" | tee out.txt + + [[ -f "${galaxy_testdir}/install/ansible_collections/ansible_test/my_collection/MANIFEST.json" ]] + grep "Installing 'ansible_test.my_collection:1.0.0' to .*" out.txt + +f_ansible_galaxy_status \ + "ansible-galaxy with a sever list with an undefined URL" + + ANSIBLE_GALAXY_SERVER_LIST=undefined ansible-galaxy collection install "ansible_test-my_collection-1.0.0.tar.gz" -p ./install --force "$@" 2>&1 | tee out.txt || echo "expected failure" + + grep "No setting was provided for required configuration plugin_type: galaxy_server plugin: undefined setting: url" out.txt + +f_ansible_galaxy_status \ + "ansible-galaxy with an empty server list" + + ANSIBLE_GALAXY_SERVER_LIST='' ansible-galaxy collection install "ansible_test-my_collection-1.0.0.tar.gz" -p ./install --force "$@" | tee out.txt [[ -f "${galaxy_testdir}/install/ansible_collections/ansible_test/my_collection/MANIFEST.json" ]] grep "Installing 'ansible_test.my_collection:1.0.0' to .*" out.txt