Unable to parse ansible/contrib/inventory/ec2.py as an inventory source

When I run the following command in the directory ansible/contrib/inventory

ansible -i ec2.py all -m ping

and I got the following error:

[WARNING]:  * Failed to parse /Users/hehe/Projects/python/ansible/contrib/inventory/ec2.py with
ini plugin: /Users/hehe/Projects/python/ansible/contrib/inventory/ec2.py:3: Error parsing host
definition ''''': No closing quotation

 [WARNING]: Unable to parse /Users/hehe/Projects/python/ansible/contrib/inventory/ec2.py as an
inventory source

 [WARNING]: No inventory was parsed, only implicit localhost is available

 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

My OS is MacOS and ansible version is 2.6.1. Did something or configurations be lost?

Odd number of the quotation marks caused the error. Fix line 3 in ec2.py

Error parsing host definition ‘’‘’': No closing quotation

Ansible is trying to read the content instead of executing the script because of missing execution bit.
So you need to set the execution bit on ec2.py to make it work.

HI Kai, thanks for your feedback. I referred to the docs: https://docs.ansible.com/ansible/latest/user_guide/intro_dynamic_inventory.html. Is it correct?

Guimin He

在 2018年10月23日星期二 UTC+8下午2:19:45,Kai Stian Olstad写道:

Yes, it actually says so:

'The easiest is to use Ansible’s -i command line option and specify
the path to the script after marking it executable:'

Dick

HI Dick, thanks for your feedback. I know this docs and the command, but this command can not work. I want to know the error reason and how I should do?

在 2018年10月23日星期二 UTC+8下午4:15:57,Dick Visser写道:

Hi Kai,

Error origin:The file you have downloaded is not marked as executable, so when you pass as inventory file, Ansible tries to read (not to execute it).
Ansible tries to read as “ini” file (you have the first warning) but, of course, this is not an ini file so it raises the warning.

Solution:
As Dick suggest, you need to mark as executable the script (chmod +x ec2.py) and launch again the ansible command (ansible -i ec2.py all -m ping).

Have you tried this solution?

You need to read the whole thread, I'm not the one with the problem.
I actually wrote the same solution that you write here to the OP.

Hi!
Kai sorry for my confusion with the names.
I answering the OP (he requested more information again).
Sorry again!

Hi Oriol, Can you give me some suggestions about this problems? Thanks in advance.

在 2018年10月24日星期三 UTC+8下午5:15:09,Oriol Tauleria写道:

Have you posted all the warnings provided? If so, it looks like you’ve disabled the script plugin, which is necessary to parse the contrib scripts. Check your ansible.cfg [inventory] enable_plugins section and the ANSIBLE_INVENTORY_ENABLED environment var.

If you just left out some of the warnings, examine the one that starts with [WARNING]: * Failed to parse /path/to/ec2.py with script plugin: to see what’s wrong. You can debug with ansible-inventory -i ec2.py --graph and by running the script alone python ec2.py.

Hi Oriol, Can you give me some suggestions about this problems? Thanks in advance.

So far 3 different people have given you such suggestions.
Please carefully read them.

Not much use in asking a 4th time...

Dick