ValueError regarding to shlex.py with dynamic inventory

366 views
Skip to first unread message

Alexander Winkler

unread,
Mar 13, 2014, 8:26:05 AM3/13/14
to ansible...@googlegroups.com
Hello,
I am currently writing an dynamic inventory to query out central database (CMDB. 
Regarding to 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 <module>
    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

Matt Martz

unread,
Mar 13, 2014, 9:29:06 AM3/13/14
to ansible...@googlegroups.com, Alexander Winkler
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.
-- 
Matt Martz
ma...@sivel.net
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/977b3aa0-540d-408e-9fc6-a0ef2ef5b0e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alexander Winkler

unread,
Mar 13, 2014, 9:42:13 AM3/13/14
to ansible...@googlegroups.com, Alexander Winkler
Hello Matt,
Just such a simple solution didn't come into my mind. It works now. Thank you!

Best regards,
Alex
Reply all
Reply to author
Forward
0 new messages