# Couldn't execute inventory file

**URL:** <https://forum.ansible.com/t/couldnt-execute-inventory-file/36437>\
**Category:** Ansible Project\
**Created:** [March 14, 2022, 11:23pm UTC](https://forum.ansible.com/t/couldnt-execute-inventory-file/36437 "2022-03-14T23:23:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Indra\_sena](https://avatars.discourse-cdn.com/v4/letter/i/ecc23a/32.png) [@Indra\_sena](https://forum.ansible.com/u/Indra_sena)\
**Post date:** [March 14, 2022, 11:23pm UTC](https://forum.ansible.com/t/couldnt-execute-inventory-file/36437/1 "2022-03-14T23:23:51Z")

</div>

Hey,

I’m unable to run the inventory file for my project. It’s throwing up few errors. please help me out.

ansible-inventory2.9.27.post0  
config file = / runner/project/ansible.cfg  
configured module search path = [‘/home/runner/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]  
ansible python module location = /usr/local/lib/python3.8/site-packages/ansible  
executable location = /usr/local/bin/ansible-inventorv  
python version = 3.8.12 (default, Sep 21 2021, 00:10:52) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]  
Using /runner/project/ansible.cfg as config file  
Reading vault password file: /runner/project/rheva/temp \_vault. txt  
setting up inventory plugins  
host\_list declined parsing /runner/project/rheva/test.py as it did not pass its verify file() method  
script declined parsing /runner/project/rheva/test.py as it did not pass its verify\_file() method  
auto declined parsing /runner/project/rheva/test.py as it did not pass its verify\_file() method  
yaml declined parsing /runner/project/rheva/test.py as it did not pass its verify\_file() method  
toml declined parsing / runner/project/rheva/test.py as it did not pass its verify\_file() method  
[WARNING]: « Failed to parse /runner/project/rheva/test.py with ini plugin:  
/runner/project/rheva/test.py:1: Expected key=value host variable assignment,  
got: psycopg2  
File “/usr/local/lib/python3.8/site-packages/ansible/inventory/manager.py”,line 280, in parse source  
plugin. parse(self.\_inventory, self.\_loader, source, cache=cache)  
File “/usr/local/lib/python3.8/site-packages/ansible/plugins/inventory/ini.py”,line 138, in parse  
raise AnsibleParserError(e)  
[WARNING]: Unable to parse /runner/proiect/rheva/test.py as an inventory source  
ERROR! No inventory was parsed, please check your configuration and options.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [March 21, 2022, 3:37pm UTC](https://forum.ansible.com/t/couldnt-execute-inventory-file/36437/2 "2022-03-21T15:37:52Z")

</div>

Sounds like `test.py` is intended to be run as a script, but was not marked as executable. Make it executable, and that should solve the problem.

---

<div class="post-metadata">

**Author:** ![Indra\_sena](https://avatars.discourse-cdn.com/v4/letter/i/ecc23a/32.png) [@Indra\_sena](https://forum.ansible.com/u/Indra_sena)\
**Post date:** [March 21, 2022, 9:07pm UTC](https://forum.ansible.com/t/couldnt-execute-inventory-file/36437/3 "2022-03-21T21:07:00Z")

</div>

I have created another executable file but even that doesn’t work and throws out following errors.

ansible-inventory2.9.27.post0  
config file = / runner/project/ansible.cfg  
configured module search path = [‘/home/runner/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]  
ansible python module location = /usr/local/lib/python3.8/site-packages/ansible  
executable location = /usr/local/bin/ansible-inventorv  
python version = 3.8.12 (default, Sep 21 2021, 00:10:52) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]

Using /runner/project/ansible.cfg as config file  
host\_list declined parsing /runner/project/rheva/tower\_inventory.py as it did not pass its verify\_file() method  
auto declined parsing /runner/project/rheva/tower\_inventory.py as it did not pass its verify\_file() method  
yaml declined parsing /runner/project/rheva/tower\_inventory.py as it did not pass its verify\_file() method  
toml declined parsing /runner/project/rheva/tower\_inventory.py as it did not pass its verify\_file() method  
[WARNING]: \* Failed to parse /runner/project/rheva/tower\_inventory.py with  
script plugin: problem running /runner/project/rheva/tower inventory.py --list  
([Errno 13] Permission denied: ‘/runner/project/rheva/tower\_ inventory.py’)  
File “/usr/local/lib/python3.8/site-packages/ansible/inventory/manager.py”, line 290, in parse source  
plugin.parse(self.\_inventory, self._loader, source, cache=cache)  
File “/ur/local/lib/python3.8/site-packages/ansible/plugins/inventory/script.py”, line 169, in parse  
raise AnsibleParserError(to\_native(e))  
[WARNING]: \* Failed to parse /runner/project/rheva/tower inventory.py with ini  
plugin: /runner/project/rheva/tower_ inventory.py:3: Expected key=value host  
variable assignment, got: os  
File “/usr/local/lib/python3.8/site-packages/ansible/inventory/manager.py”, line 290, in parse\_source  
plugin.parse(self.\_inventory, self._loader, source, cache=cache)  
File “/usr/local/lib/python3.8/site-packages/ansible/plugins/inventory/ini.py”,line136,inparse  
raise AnsibleParserError(e)  
[WARNING]: Unable to parse /runner/project/rheva/tower_ inventory.py as an  
inventory source  
ERROR! No inventory was parsed, please check your configuration and options.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [March 21, 2022, 9:12pm UTC](https://forum.ansible.com/t/couldnt-execute-inventory-file/36437/4 "2022-03-21T21:12:26Z")

</div>

The script plugin reports:

([Errno 13] Permission denied: ‘/runner/project/rheva/tower\_ inventory.py’)

This indicates that the file is not actually marked as executable.

---

<div class="post-metadata">

**Author:** ![Indra\_sena](https://avatars.discourse-cdn.com/v4/letter/i/ecc23a/32.png) [@Indra\_sena](https://forum.ansible.com/u/Indra_sena)\
**Post date:** [March 21, 2022, 11:03pm UTC](https://forum.ansible.com/t/couldnt-execute-inventory-file/36437/5 "2022-03-21T23:03:31Z")

</div>

Hello Matt,

I’ve given the execution permission again and retried but it still throws out few errors. Please resolve the issue. I’m also posting my tower inventory python script. Please help me out. Thanks a lot!

Below is the errors I received.

[ansible-inventory2.9.27.post0  
config file = / runner/project/ansible.cfg  
configured module search path = [‘/home/runner/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]  
ansible python module location = /usr/local/lib/python3.8/site-packages/ansible  
executable location = /usr/local/bin/ansible-inventorv  
python version = 3.8.12 (default, Sep 21 2021, 00:10:52) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]

Using /runner/project/ansible.cfg as config file

host\_list declined parsing /runner/project/rheva/tower\_inventory.py as it did not pass its verify\_file() method  
auto declined parsing /runner/project/rheva/tower\_inventory.py as it did not pass its verify\_file() method  
yaml declined parsing /runner/project/rheva/tower\_inventory.py as it did not pass its verify\_file() method  
toml declined parsing /runner/project/rheva/tower\_inventory.py as it did not pass its verify\_file() method

[WARNING]: \* Failed to parse /runner/project/rheva/tower\_inventory. py with  
script plugin: Inventory script (/runner/project/rheva/tower\_inventory.py) had  
an execution error: Traceback (most recent  
call last):  
File “/runner/project/rheva/tower\_inventory.py”, line 58, in TowerInventory()  
File “/runner/project/rheva/tower\_inventory.py”, line 16, in init.  
self.inventory = self. tower\_ inventory()  
File “/runner/project/rheva/tower\_inventory.py”,  
Line 29. in tower inventory  
tmp\_inventory = ({ tower \_inventory | to\_nice\_json }} NameError: name  
"tower inventory’ is not defined  
File “/sr/local/lib/python3.8/site-packages/ansible/inventory/manager.py”, line 280, in parse\_source  
plugin.parse(self.\_inventory, self.\_loader, source, cache=cache)  
File “/usr/local/lib/python3.8/site-packages/ansible/plugins/inventory/script.py”, line 161, in parse  
raise AnsibleParserError(to\_native(e))  
[WARNING]: \* Failed to parse /runner/project/rheva/tower inventory.py with ini  
plugin: /runner/project/rheva/tower\_inventory.py:3: Expected key=value host  
variable assignment, got: os  
File “/usr/local/lib/python3.8/site-packages/ansible/inventory/manager.py”, line 280, in parse\_source  
plugin.parse(self.\_inventory, self.\_loader, source, cache=cache)  
File “/usr/local/lib/python3.8/site-packages/ansible/plugins/inventory/ini.py”,line138,inparse  
raise AnsibleParserError(e)  
[WARNING]: Unable to parse /runner/project/rheva/tower inventory.py as an  
inventory source  
ERROR! No inventory was parsed, please check your configuration and options.]

The tower\_inventory.py script is shown below:

_import os_

_import sys_

_import argparse_

_import json_

_class TowerInventory(object):_

_def **init** (self):_

_self.inventory = {}_

_self.read\_cli\_args()_

_# Called with `--list`._

_if self.args.list:_

_self.inventory = self.tower\_inventory()_

_# Called with `--host [hostname]`._

_elif self.args.host:_

_# Not implemented, since we return \_meta info `--list`._

_self.inventory = self.empty\_inventory()_

_# If no groups or vars are present, return an empty inventory._

_else:_

_self.inventory = self.empty\_inventory()_

_print (json.dumps(self.inventory));_

_# Tower inventory for testing._

_def tower\_inventory(self):_

_tmp\_inventory = {{ tower\_inventory | to\_nice\_json }}_

_tmp\_inventory = remove\_empty\_elements(tmp\_inventory)_

_return tmp\_inventory_

_# Empty inventory for testing._

_def empty\_inventory(self):_

_return {“\_meta”: {“hostvars”: {}}}_

_# Read the command line args passed to the script._

_def read\_cli\_args(self):_

_parser = argparse.ArgumentParser()_

_parser.add\_argument(“–list”, action = “store\_true”)_

_parser.add\_argument(“–host”, action = “store”)_

_self.args = parser.parse\_args()_

_# Remove empty groups and elements from dict_

_def remove\_empty\_elements(d):_

_“”“recursively remove empty lists, empty dicts, or None elements from a dictionary”“”_

_def empty(x):_

_return x is None or x == {} or x == [] or x == [“”]_

_if not isinstance(d, (dict, list)):_

_return d_

_elif isinstance(d, list):_

_return [v for v in (remove\_empty\_elements(v) for v in d) if not empty(v)]_

_else:_

_return {k: v for k, v in ((k, remove\_empty\_elements(v)) for k, v in list(d.items())) if not empty(v)}_

_# Get the inventory._

_TowerInventory()_
