Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ansible-galaxy crashes with invalid token file #70887

Closed
kbreit opened this issue Jul 24, 2020 · 7 comments · Fixed by #70911
Closed

ansible-galaxy crashes with invalid token file #70887

kbreit opened this issue Jul 24, 2020 · 7 comments · Fixed by #70911
Labels
affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. has_pr This issue has an associated PR. python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback.

Comments

@kbreit
Copy link
Contributor

kbreit commented Jul 24, 2020

SUMMARY

I had a galaxy-token file which wasn't valid YAML and thus ansible-galaxy when crashing when installing a collection. While it's fine that it's failing, it should provide some details about why it failed.

@jborean93

ISSUE TYPE
  • Bug Report
COMPONENT NAME

ansible-galaxy

ANSIBLE VERSION
ansible 2.9.10
  config file = /Users/kbreit/Documents/Programming/config_check/ansible.cfg
  configured module search path = ['/Users/kbreit/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/2.9.10/libexec/lib/python3.8/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.8.5 (default, Jul 21 2020, 10:48:26) [Clang 11.0.3 (clang-1103.0.32.62)]

OS / ENVIRONMENT

macOS 10.15.5

STEPS TO REPRODUCE

Try to install a module using ansible-galaxy collection install with an invalid syntax'd YAML file for your ~/.ansible/galaxy_token`

EXPECTED RESULTS
ACTUAL RESULTS
config_check [kbreit/diff●●] % ansible-galaxy collection install cisco.nxos -vvv
ansible-galaxy 2.9.10
  config file = /Users/kbreit/Documents/Programming/config_check/ansible.cfg
  configured module search path = ['/Users/kbreit/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/2.9.10/libexec/lib/python3.8/site-packages/ansible
  executable location = /usr/local/bin/ansible-galaxy
  python version = 3.8.5 (default, Jul 21 2020, 10:48:26) [Clang 11.0.3 (clang-1103.0.32.62)]
Using /Users/kbreit/Documents/Programming/config_check/ansible.cfg as config file
Process install dependency map
Opened /Users/kbreit/.ansible/galaxy_token
Processing requirement collection 'cisco.nxos'
ERROR! Unexpected Exception, this is probably a bug: 'str' object has no attribute 'get'
the full traceback was:

Traceback (most recent call last):
  File "/usr/local/bin/ansible-galaxy", line 123, in <module>
    exit_code = cli.run()
  File "/usr/local/Cellar/ansible/2.9.10/libexec/lib/python3.8/site-packages/ansible/cli/galaxy.py", line 375, in run
    context.CLIARGS['func']()
  File "/usr/local/Cellar/ansible/2.9.10/libexec/lib/python3.8/site-packages/ansible/cli/galaxy.py", line 836, in execute_install
    install_collections(requirements, output_path, self.api_servers, (not ignore_certs), ignore_errors,
  File "/usr/local/Cellar/ansible/2.9.10/libexec/lib/python3.8/site-packages/ansible/galaxy/collection.py", line 457, in install_collections
    dependency_map = _build_dependency_map(collections, existing_collections, b_temp_path, apis,
  File "/usr/local/Cellar/ansible/2.9.10/libexec/lib/python3.8/site-packages/ansible/galaxy/collection.py", line 821, in _build_dependency_map
    _get_collection_info(dependency_map, existing_collections, name, version, source, b_temp_path, apis,
  File "/usr/local/Cellar/ansible/2.9.10/libexec/lib/python3.8/site-packages/ansible/galaxy/collection.py", l  1 token: e2167b20b5f989bd113fedbefcc345261e9eee8b
ine 894, in _get_collection_info
    collection_info = CollectionRequirement.from_name(collection, apis, requirement, force, parent=parent)
  File "/usr/local/Cellar/ansible/2.9.10/libexec/lib/python3.8/site-packages/ansible/galaxy/collection.py", line 346, in from_name
    resp = api.get_collection_versions(namespace, name)
  File "/usr/local/Cellar/ansible/2.9.10/libexec/lib/python3.8/site-packages/ansible/galaxy/api.py", line 56, in wrapped
    data = self._call_galaxy(n_url, method='GET', error_context_msg=error_context_msg)
  File "/usr/local/Cellar/ansible/2.9.10/libexec/lib/python3.8/site-packages/ansible/galaxy/api.py", line 192, in _call_galaxy
    self._add_auth_token(headers, url, required=auth_required)
  File "/usr/local/Cellar/ansible/2.9.10/libexec/lib/python3.8/site-packages/ansible/galaxy/api.py", line 222, in _add_auth_token
    headers.update(self.token.headers())
  File "/usr/local/Cellar/ansible/2.9.10/libexec/lib/python3.8/site-packages/ansible/galaxy/token.py", line 148, in headers
    token = self.get()
  File "/usr/local/Cellar/ansible/2.9.10/libexec/lib/python3.8/site-packages/ansible/galaxy/token.py", line 140, in get
    return self.config.get('token', None)
AttributeError: 'str' object has no attribute 'get'
@ansibot
Copy link
Contributor

ansibot commented Jul 24, 2020

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot ansibot added affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback. labels Jul 24, 2020
@bmillemathias
Copy link
Contributor

Hello,

thanks for the report.
Out of curiosity the corruption was because of an action of you or could be related to ansible ?

@bmillemathias
Copy link
Contributor

bmillemathias commented Jul 26, 2020

I'd be interested if you could share how looks like the token because I modified my token file to not be yaml and I got not exception, only a standard yaml format error (running ansible development version 2.10rc2)

ERROR! Unexpected Exception, this is probably a bug: mapping values are not allowed here
  in "b'/home/baptistemm/.ansible/galaxy_token'", line 2, column 6

edit: Ok, with -vvv I get an exception but I think this is expected to trace the code source of the issue.

@bmillemathias
Copy link
Contributor

need_info

@kbreit
Copy link
Contributor Author

kbreit commented Jul 26, 2020

My token file was just a plain file with only the token, nothing else.

@jborean93
Copy link
Contributor

The error here is not when the file has invalid yaml but rather when the yaml structure is not a dictionary. We expect it to be a yaml as a dict so basically

token: token_value

When the file is just token_value it's parsed as a string. So both cases are not something we can fix but they are definitely cases we can provide a better error message around.

Akasurde added a commit to Akasurde/ansible that referenced this issue Jul 27, 2020
Malformed galaxy_token file creates stacktrace.

Fixes: ansible#70887

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
Akasurde added a commit to Akasurde/ansible that referenced this issue Jul 28, 2020
Malformed galaxy_token file creates stacktrace.

Fixes: ansible#70887

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
@samdoran samdoran added has_pr This issue has an associated PR. and removed needs_triage Needs a first human triage before being processed. labels Jul 28, 2020
Akasurde added a commit to Akasurde/ansible that referenced this issue Aug 3, 2020
Malformed galaxy_token file creates stacktrace.

Fixes: ansible#70887

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
@Akasurde
Copy link
Member

resolved_by_pr #70911

s-hertel pushed a commit that referenced this issue Dec 21, 2020
Malformed galaxy_token file creates stacktrace.

Fixes: #70887

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
@ansible ansible locked and limited conversation to collaborators Jan 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. has_pr This issue has an associated PR. python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants