diff --git a/changelogs/fragments/70375-galaxy-server.yml b/changelogs/fragments/70375-galaxy-server.yml new file mode 100644 index 00000000000..1cb733744ca --- /dev/null +++ b/changelogs/fragments/70375-galaxy-server.yml @@ -0,0 +1,4 @@ +bugfixes: +- ansible-galaxy - Instead of assuming the first defined server is galaxy, + filter based on the servers that support the v1 API, and return the first + of those (https://github.com/ansible/ansible/issues/65440) diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py index 0a22298f8d2..9bd5bafbc90 100644 --- a/lib/ansible/cli/galaxy.py +++ b/lib/ansible/cli/galaxy.py @@ -114,6 +114,7 @@ class GalaxyCLI(CLI): self.api_servers = [] self.galaxy = None + self._api = None super(GalaxyCLI, self).__init__(args) def init_parser(self): @@ -499,7 +500,21 @@ class GalaxyCLI(CLI): @property def api(self): - return self.api_servers[0] + if self._api: + return self._api + + for server in self.api_servers: + try: + if u'v1' in server.available_api_versions: + self._api = server + break + except Exception: + continue + + if not self._api: + self._api = self.api_servers[0] + + return self._api def _get_default_collection_path(self): return C.COLLECTIONS_PATHS[0]