I've seen a few posts on this topic with odd hard to reproduce behaviours. Here's a new set of data points.

Currently the following works

cd ./hosts
./ec2.py --profile=dev


And this fails

AWS_PROFILE=dev; ansible-playbook test.yml
These were both working a couple days ago.  Something in my environment changed. Still investigating. Any guesses?
Error message:
ERROR! The file ./hosts/ec2.py is marked as executable, but failed to execute correctly. If this is not supposed to be an executable script, correct this withchmod -x ./hosts/ec2.py.
ERROR! Inventory script (./hosts/ec2.py) had an execution error: ERROR: "Error connecting to AWS backend.
You are not authorized to perform this operation.", while: getting EC2 instances
ERROR! ./hosts/ec2.py:3: Error parsing host definition ''''': No closing quotation

Note that the normal credentials error is:
ERROR: "Error connecting to AWS backend.
You are not authorized to perform this operation.", while: getting EC2 instances
...
Hmmm. Error message has shifted. 

AWS_PROFILE=dev; ansible-playbook test.yml
ERROR! ERROR! ./hosts/tmp:2: Expected key=value host variable assignment, got: {
Looks like the problem was a temporary file in the hosts folder.  After removing it the problems went away.  It looks like std ansible behaviour: Pull in ALL files in the hosts folder.
Ansible ec2.py runs standalone but fails in playbook