# ValueError regarding to shlex.py with dynamic inventory

**URL:** <https://forum.ansible.com/t/valueerror-regarding-to-shlex-py-with-dynamic-inventory/14764>\
**Category:** Ansible Project\
**Created:** [March 13, 2014, 12:26pm UTC](https://forum.ansible.com/t/valueerror-regarding-to-shlex-py-with-dynamic-inventory/14764 "2014-03-13T12:26:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_Winkler](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@Alexander\_Winkler](https://forum.ansible.com/u/Alexander_Winkler)\
**Post date:** [March 13, 2014, 12:26pm UTC](https://forum.ansible.com/t/valueerror-regarding-to-shlex-py-with-dynamic-inventory/14764/1 "2014-03-13T12:26:05Z")

</div>

Hello,  
I am currently writing an dynamic inventory to query out central database (CMDB.  
Regarding to [http://docs.ansible.com/developing\_inventory.html](http://docs.ansible.com/developing_inventory.html), I am implementing the \_meta field for host variables. As far as I understood, “\_meta” resolves in the function “–host” to be deprecated. So i just wrote a ‘stupid’ script without any parameters.  
My output looks like this:

{  
“ungrouped”: {  
“hosts”: [  
“ServerA”,  
“ServerB”  
]

},  
“\_meta”: {  
“hostvars”: {  
“ServerA”: {  
“ansible\_ssh\_host”: “192.168.0.1”  
},  
“ServerB”: {  
“ansible\_ssh\_host”: “192.168.0.2”  
}  
}  
}  
}

Everything should be fine. But running ansible produces the following error (Ignore the first 2 lines. Those are warnings regarding to the SLES version of libraries):

user@host ~/git/ansible $ ansible-playbook site.yml -i /tmp/dyn\_cmdb\_inv.py  
/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 “/usr/bin/ansible-playbook”, line 269, in   
sys.exit(main(sys.argv[1:]))  
File “/usr/bin/ansible-playbook”, line 86, in main  
inventory = ansible.inventory.Inventory(options.inventory)  
File “/usr/lib64/python2.6/site-packages/ansible/inventory/ **init**.py”, line 105, in **init**  
self.parser = InventoryParser(filename=host\_list)  
File “/usr/lib64/python2.6/site-packages/ansible/inventory/ini.py”, line 41, in **init**  
self.\_parse()  
File “/usr/lib64/python2.6/site-packages/ansible/inventory/ini.py”, line 45, in \_parse  
self.\_parse\_base\_groups()  
File “/usr/lib64/python2.6/site-packages/ansible/inventory/ini.py”, line 83, in \_parse\_base\_groups  
tokens = shlex.split(line)  
File “/usr/lib64/python2.6/shlex.py”, line 279, in split  
return list(lex)  
File “/usr/lib64/python2.6/shlex.py”, line 269, in next  
token = self.get\_token()  
File “/usr/lib64/python2.6/shlex.py”, line 96, in get\_token  
raw = self.read\_token()  
File “/usr/lib64/python2.6/shlex.py”, line 172, in read\_token  
raise ValueError, “No closing quotation”  
ValueError: No closing quotation

Do you have any hint, why this error is produced? All quotations and formats are correct. The output is generated in python with “print (json.dumps(inventory, cls=DateEncoder, indent=4))”, while “inventory” is a dictionary.

Thank you.  
Alex

---

<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 13, 2014, 1:29pm UTC](https://forum.ansible.com/t/valueerror-regarding-to-shlex-py-with-dynamic-inventory/14764/2 "2014-03-13T13:29:06Z")

</div>

From that traceback, it appears as though your inventory script is being parsed by the ini parser.

That is an indication that your inventory script has not been set as executable. (chmod +x /path/to/inventory/script)

Ansible determines whether it is an ini file or script by detecting if the file is executable.

---

<div class="post-metadata">

**Author:** ![Alexander\_Winkler](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@Alexander\_Winkler](https://forum.ansible.com/u/Alexander_Winkler)\
**Post date:** [March 13, 2014, 1:42pm UTC](https://forum.ansible.com/t/valueerror-regarding-to-shlex-py-with-dynamic-inventory/14764/3 "2014-03-13T13:42:13Z")

</div>

Hello Matt,  
Just such a simple solution didn’t come into my mind. It works now. Thank you!

Best regards,  
Alex
