title: Unable to parse inventory script as an inventory
body: <p>My python script dynamically queries and generates a JSON file as follows:</p>
  
  <pre><code>{
      "all": {
        "hosts": [
          "192.158.1.1"
        ], 
        "vars": {
          "ansible_become_method": "sudo", 
          "ansible_become": "yes"
        }
      }
    }
  </code></pre>
  
  <p>But somehow when I execute the command below</p>
  
  <pre><code>ansible -i script.py -m ping 
  </code></pre>
  
  <p>it gives out the following warning messages</p>
  
  <ul>
  <li>[WARNING] Unable to parse /etc/ansible/script.py as an inventory source</li>
  <li>[WARNING] No inventory was parse, only implicit localhost is available.</li>
  <li>[WARNING] provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'</li>
  </ul>
  
  <p>I don't know what I'm missing or wrong as I'm new to dynamic inventory with Ansible.</p>
  
  <p>When I run <code>ansible-inventory -i script.py --list</code> I got the following response</p>
  
  <pre><code>{
      "_meta": {
          "hostvars": {}
      }, 
      "all": {
          "children": [
              "ungrouped"
          ]
      }, 
      "ungrouped": {}
  }
  </code></pre>
  
  <p>My Ansible version is 2.7.7</p>
  
  <p>Inventory plugin is script</p>
  
  <pre><code>enable_plugins = script
  </code></pre>
  
  <p><strong>[Updated]</strong> Running -v based on Steve's suggestion gives me a bit more</p>
  
  <pre><code> [WARNING]:  * Failed to parse /etc/ansible/newhost.py with script plugin: failed to parse executable inventory script results from /etc/ansible/script.py: Syntax
  Error while loading YAML.   mapping values are not allowed in this context  The error appears to have been in '&lt;string&gt;': line 3, column 8, but may be elsewhere in the
  file depending on the exact syntax problem.
  
  
   File "/usr/lib/python2.7/site-packages/ansible/plugins/inventory/script.py", line 125, in parse
      raise AnsibleError("failed to parse executable inventory script results from {0}: {1}\n{2}".format(path, to_native(e), err))
  </code></pre>