ansible / galaxy

Legacy Galaxy still available as read-only on https://old-galaxy.ansible.com - looking for the new galaxy -> https://github.com/ansible/galaxy_ng
Apache License 2.0
852 stars 330 forks source link

Import fails with "No JSON object could be decoded" if a failed attempt exists #318

Open siamaksade opened 6 years ago

siamaksade commented 6 years ago

If a failed attempt exists for a sepcific role name, consequent imports keep using the failed attempt options and keep failing.

I had imported a role with the wrong syntax (github user an repo) which of course failed:

screen shot 2018-02-05 at 10 29 35

Correcting the syntax does not help now and keeps failing with the same error as long as the role name is the same as the failed attemp, openshift_nexus in this case:

$ ansible-galaxy -vvv import --role-name=openshift_nexus siamaksade ansible-openshift-nexus

ansible-galaxy 2.4.1.0
  config file = None
  configured module search path = [u'/Users/ssadeghi/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Library/Python/2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible-galaxy
  python version = 2.7.10 (default, Jul 15 2017, 17:16:57) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)]
No config file found; using defaults
Opened /Users/ssadeghi/.ansible_galaxy
https://galaxy.ansible.com/api/v1/imports/
ERROR! Unexpected Exception, this is probably a bug: No JSON object could be decoded
the full traceback was:

Traceback (most recent call last):
  File "/usr/local/bin/ansible-galaxy", line 106, in <module>
    exit_code = cli.run()
  File "/Library/Python/2.7/site-packages/ansible/cli/galaxy.py", line 150, in run
    self.execute()
  File "/Library/Python/2.7/site-packages/ansible/cli/__init__.py", line 154, in execute
    fn()
  File "/Library/Python/2.7/site-packages/ansible/cli/galaxy.py", line 586, in execute_import
    task = self.api.create_import_task(github_user, github_repo, reference=self.options.reference, role_name=self.options.role_name)
  File "/Library/Python/2.7/site-packages/ansible/galaxy/api.py", line 56, in wrapped
    return method(self, *args, **kwargs)
  File "/Library/Python/2.7/site-packages/ansible/galaxy/api.py", line 155, in create_import_task
    data = self.__call_galaxy(url, args=urlencode(args))
  File "/Library/Python/2.7/site-packages/ansible/galaxy/api.py", line 56, in wrapped
    return method(self, *args, **kwargs)
  File "/Library/Python/2.7/site-packages/ansible/galaxy/api.py", line 96, in __call_galaxy
    res = json.loads(to_text(e.fp.read(), errors='surrogate_or_strict'))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

If the role name is changed to something else e.g. ocp_nexus instead of openshift_nexus, then the import would succeed:

ansible-galaxy -vvv import --role-name=ocp_nexus siamaksade ansible-openshift-nexus
chouseknecht commented 6 years ago

@siamaksade

Not sure I follow the chain of events. I am able to reproduce the error, ValueError: No JSON object could be decoded, by running the following:

ansible-galaxy -vvv import --role-name=openshift_nexus chouseknecht chouseknecht/ansible-openshift-nexus

But then, if I immediately run the following, it works just fine:

ansible-galaxy -vvv import --role-name=openshift_nexus chouseknecht ansible-openshift-nexus

I do see that you have the role already imported as openshift_sonatype_nexus, and so I wonder if that's the issue.

My suggestion would be to delete the role from Galaxy, and import it from scratch.

chouseknecht commented 6 years ago

My take away from experimenting with POST requests to api/v1/imports is that we need to verify the requested github_user and github_repo with the GitHub API, and when not valid, return an error that the client can process.

siamaksade commented 6 years ago

I imported it under a different name since it kept failing with openshift_nexus as the role name. I couldn't delete it since it kept saying such a role doesn't exist. It seemed like it is left in an inconsistent state that delete says it doesn't exist, and import uses the same incorrect github repo as the first import command no matter what the consequent commands specify as the github repo.

anjo-swe commented 6 years ago

Similar issue on our end today:

30-Jul-2018 15:21:07    - downloading role 'logrotate', owned by ssilab
30-Jul-2018 15:21:07    https://galaxy.ansible.com/api/v1/roles/?owner__username=ssilab&name=logrotate
30-Jul-2018 15:21:07    Unexpected Exception: No JSON object could be decoded

When i actually go to the URL mentioned i get the real error:

Request URL: https://galaxy.ansible.com/api/v1/roles/?owner__username=ssilab&name=logrotate
Request Method: GET
Status Code: 500 Internal Server Error
haidaraM commented 6 years ago

Similar issue too. The website also seems broken