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

**URL:** <https://forum.ansible.com/t/unable-to-parse-ansible-contrib-inventory-ec2-py-as-an-inventory-source/28848>\
**Category:** Ansible Project\
**Created:** [October 23, 2018, 1:42am UTC](https://forum.ansible.com/t/unable-to-parse-ansible-contrib-inventory-ec2-py-as-an-inventory-source/28848 "2018-10-23T01:42:29Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![heguimin36](https://avatars.discourse-cdn.com/v4/letter/h/ec9cab/32.png) [@heguimin36](https://forum.ansible.com/u/heguimin36)\
**Post date:** [October 23, 2018, 1:42am UTC](https://forum.ansible.com/t/unable-to-parse-ansible-contrib-inventory-ec2-py-as-an-inventory-source/28848/1 "2018-10-23T01:42:29Z")

</div>

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

```auto
ansible -i ec2.py all -m ping

```

and I got the following error:

```auto
[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?

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [October 23, 2018, 6:08am UTC](https://forum.ansible.com/t/unable-to-parse-ansible-contrib-inventory-ec2-py-as-an-inventory-source/28848/2 "2018-10-23T06:08:17Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 23, 2018, 6:19am UTC](https://forum.ansible.com/t/unable-to-parse-ansible-contrib-inventory-ec2-py-as-an-inventory-source/28848/3 "2018-10-23T06:19:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![heguimin36](https://avatars.discourse-cdn.com/v4/letter/h/ec9cab/32.png) [@heguimin36](https://forum.ansible.com/u/heguimin36)\
**Post date:** [October 23, 2018, 7:02am UTC](https://forum.ansible.com/t/unable-to-parse-ansible-contrib-inventory-ec2-py-as-an-inventory-source/28848/4 "2018-10-23T07:02:06Z")

</div>

HI Kai, thanks for your feedback. I referred to the docs: [https://docs.ansible.com/ansible/latest/user\_guide/intro\_dynamic\_inventory.html](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写道：

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [October 23, 2018, 8:15am UTC](https://forum.ansible.com/t/unable-to-parse-ansible-contrib-inventory-ec2-py-as-an-inventory-source/28848/5 "2018-10-23T08:15:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![heguimin36](https://avatars.discourse-cdn.com/v4/letter/h/ec9cab/32.png) [@heguimin36](https://forum.ansible.com/u/heguimin36)\
**Post date:** [October 23, 2018, 3:25pm UTC](https://forum.ansible.com/t/unable-to-parse-ansible-contrib-inventory-ec2-py-as-an-inventory-source/28848/6 "2018-10-23T15:25:13Z")

</div>

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写道：

---

<div class="post-metadata">

**Author:** ![Oriol\_Tauleria](https://avatars.discourse-cdn.com/v4/letter/o/58f4c7/32.png) [@Oriol\_Tauleria](https://forum.ansible.com/u/Oriol_Tauleria)\
**Post date:** [October 24, 2018, 7:22am UTC](https://forum.ansible.com/t/unable-to-parse-ansible-contrib-inventory-ec2-py-as-an-inventory-source/28848/7 "2018-10-24T07:22:06Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 24, 2018, 7:43am UTC](https://forum.ansible.com/t/unable-to-parse-ansible-contrib-inventory-ec2-py-as-an-inventory-source/28848/8 "2018-10-24T07:43:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Oriol\_Tauleria](https://avatars.discourse-cdn.com/v4/letter/o/58f4c7/32.png) [@Oriol\_Tauleria](https://forum.ansible.com/u/Oriol_Tauleria)\
**Post date:** [October 24, 2018, 9:14am UTC](https://forum.ansible.com/t/unable-to-parse-ansible-contrib-inventory-ec2-py-as-an-inventory-source/28848/9 "2018-10-24T09:14:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![heguimin36](https://avatars.discourse-cdn.com/v4/letter/h/ec9cab/32.png) [@heguimin36](https://forum.ansible.com/u/heguimin36)\
**Post date:** [October 24, 2018, 12:02pm UTC](https://forum.ansible.com/t/unable-to-parse-ansible-contrib-inventory-ec2-py-as-an-inventory-source/28848/10 "2018-10-24T12:02:20Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![shertel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/shertel/32/1241_2.png) [@shertel](https://forum.ansible.com/u/shertel)\
**Post date:** [October 24, 2018, 5:12pm UTC](https://forum.ansible.com/t/unable-to-parse-ansible-contrib-inventory-ec2-py-as-an-inventory-source/28848/11 "2018-10-24T17:12:05Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [October 24, 2018, 6:17pm UTC](https://forum.ansible.com/t/unable-to-parse-ansible-contrib-inventory-ec2-py-as-an-inventory-source/28848/12 "2018-10-24T18:17:15Z")

</div>

> 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
