external inventory problem

Hi I’m experimenting with an external inventory script and I’ve run into some troubles.

root@vader:ansible $ ansible -i inventory.php -m ping all
Traceback (most recent call last):
File “/usr/bin/ansible”, line 156, in
(runner, results) = cli.run(options, args)
File “/usr/bin/ansible”, line 81, in run
inventory_manager = inventory.Inventory(options.inventory)
File “/usr/lib/python2.6/site-packages/ansible/inventory/init.py”, line 87, in init
self.parser = InventoryScript(filename=host_list)
File “/usr/lib/python2.6/site-packages/ansible/inventory/script.py”, line 45, in init
self.groups = self._parse(stderr)
File “/usr/lib/python2.6/site-packages/ansible/inventory/script.py”, line 59, in _parse
for (group_name, data) in self.raw.items():
AttributeError: ‘list’ object has no attribute ‘items’

My script’s output seems (to me at least) to be correct and it validates :
root@vader:ansible $ ./inventory.php -list
[{“spare”:[“cmldap11.otenet.gr”,“cmldap1.otenet.gr”,“cmldap2.otenet.gr”,“cmldap10.otenet.gr”,“cmldap7.otenet.gr”,“cmldap8.otenet.gr”,“cmldap9.otenet.gr”,“cmldap3.otenet.gr”,“cmldap4.otenet.gr”,“cmldap5.otenet.gr”,“cmldap6.otenet.gr”,“ca-be-1”,“ca-be-2”,“SPARE”,“SPARE”,“SPARE”]}]

Am I missing something ?

​Looks like you are returning a list (of a dict) instead of returning a
dict.

Ah yes you’re right. It turns out my server’s PHP version doesn’t support encoding an array as a dict, so I rewrote my script in python.
Works great now, thank you!