Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible EC2 Python Error: ValueError: No JSON object could be decoded

I was merrily going on my way, everything was working, and suddenly I'm getting errors from all my EC2 Ansible operations (The warning about rebuilding was there before and not an issue):

ec2-user]# ansible -m ping -u ec2-user all
/usr/lib64/python2.6/site-packages/Crypto/Util/number.py:57: PowmInsecureWarning: Not using mpz_powm_sec.  You should rebuild using libgmp >= 5 to avoid timing attack vulnerability.
  _warn("Not using mpz_powm_sec.  You should rebuild using libgmp >= 5 to avoid timing attack vulnerability.", PowmInsecureWarning)
Traceback (most recent call last):
  File "/root/ansible/bin/ansible", line 194, in <module>
    (runner, results) = cli.run(options, args)
  File "/root/ansible/bin/ansible", line 112, in run
    inventory_manager = inventory.Inventory(options.inventory, vault_password=vault_pass)
  File "/root/ansible/lib/ansible/inventory/__init__.py", line 118, in __init__
    self.parser = InventoryScript(filename=host_list)
  File "/root/ansible/lib/ansible/inventory/script.py", line 49, in __init__
    self.groups = self._parse(stderr)
  File "/root/ansible/lib/ansible/inventory/script.py", line 57, in _parse
    self.raw  = utils.parse_json(self.data)
  File "/root/ansible/lib/ansible/utils/__init__.py", line 552, in parse_json
    results = json.loads(data)
  File "/usr/lib64/python2.6/json/__init__.py", line 307, in loads
    return _default_decoder.decode(s)
  File "/usr/lib64/python2.6/json/decoder.py", line 319, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib64/python2.6/json/decoder.py", line 338, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

Anyone know what gives?

If I try to runs hosts I get:

 ec2-user]# /etc/ansible/hosts
Looks like AWS is down again:
EC2ResponseError: 403 Forbidden
<?xml version="1.0" encoding="UTF-8"?>
<Response><Errors><Error><Code>UnauthorizedOperation</Code><Message>You are not authorized to perform this operation.</Message></Error></Errors><RequestID>9c499f04-3fd8-47cd-a7e4-655af47c1564</RequestID></Response>

All my operations in the AWS console are still successful.

like image 351
mtyson Avatar asked Dec 06 '14 15:12

mtyson


2 Answers

I ran into this issue as well. Turned out to be a problem with my AWS keys. Here's what I would suggest:

  1. Verify that you have valid keys. I know this seems obvious, but start here :-)
  2. If you're using export AWS_SECRET_ACCESS_KEY=... to set them in your environment, it's important that the punctuation around them be correct. Mine look like

export AWS_ACCESS_KEY_ID="ASFSADFSDF" (with quotes)

export AWS_SECRET_ACCESS_KEY=ADSFASFAASFASDFSADSFDASDFSADF (no quotes)

  1. If you're setting these in a .zshconfig or .bash_profile, restart your tab or window to make sure that the config file gets reread and your AWS keys are loaded into the environment.

Hope that helps!

like image 119
rossettistone Avatar answered Sep 27 '22 22:09

rossettistone


  1. Make sure you have AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY exported. (as others have pointed)

  2. Make sure you have boto installed, you can install it by running :

    sudo pip install boto

like image 25
Eran Chetzroni Avatar answered Sep 27 '22 23:09

Eran Chetzroni