From aa9cbada69bd10b42835ad89e047f0f9ed0fea13 Mon Sep 17 00:00:00 2001 From: s-hertel <19572925+s-hertel@users.noreply.github.com> Date: Wed, 22 Nov 2023 12:24:16 -0500 Subject: [PATCH] Avoid creating GALAXY_TOKEN_PATH for configured ansible-galaxy server list changelog --- .../fragments/ansible-galaxy-fix-tokenfile-creation.yml | 2 ++ lib/ansible/cli/galaxy.py | 2 +- lib/ansible/galaxy/token.py | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/ansible-galaxy-fix-tokenfile-creation.yml diff --git a/changelogs/fragments/ansible-galaxy-fix-tokenfile-creation.yml b/changelogs/fragments/ansible-galaxy-fix-tokenfile-creation.yml new file mode 100644 index 00000000000..a5c5fb4299f --- /dev/null +++ b/changelogs/fragments/ansible-galaxy-fix-tokenfile-creation.yml @@ -0,0 +1,2 @@ +bugfixes: + - ansible-galaxy - avoid creating the ``GALAXY_TOKEN_PATH`` as a side effect of configured servers that don't use ``username``/``password`` or ``auth_url`` for authentication. diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py index 07e652a2e95..0f85a0abcd6 100755 --- a/lib/ansible/cli/galaxy.py +++ b/lib/ansible/cli/galaxy.py @@ -693,7 +693,7 @@ class GalaxyCLI(CLI): client_id=client_id) else: # The galaxy v1 / github / django / 'Token' - server_options['token'] = GalaxyToken(token=token_val) + server_options['token'] = GalaxyToken(token=token_val, config={}) server_options.update(galaxy_options) config_servers.append(GalaxyAPI( diff --git a/lib/ansible/galaxy/token.py b/lib/ansible/galaxy/token.py index 183e2af109e..400336ffdfc 100644 --- a/lib/ansible/galaxy/token.py +++ b/lib/ansible/galaxy/token.py @@ -102,10 +102,10 @@ class GalaxyToken(object): token_type = 'Token' - def __init__(self, token=None): + def __init__(self, token=None, config=None): self.b_file = to_bytes(C.GALAXY_TOKEN_PATH, errors='surrogate_or_strict') # Done so the config file is only opened when set/get/save is called - self._config = None + self._config = config self._token = token @property