inventory not being able to read when using ansible 2 api

Here is my structure.

✗ tree -L 2
.
├── ansible.cfg
├── ansible.cfg.bak
├── group_vars
│ ├── default
│ └── default.bak
├── hosts
├── playbook.yml
├── playbook_hostname.yml
├── playbook_ip.yml
├── roles
│ ├── hostname
│ ├── ip
│ └── satellite

When i run the below code, i am not able to connect to the remote machine. When i check with tcpdump, no connection request is sent, it seems somehow no connection details are read from inventory files.

This is the error i saw when i install the ansible 2.0.0.1

raise AnsibleError(“no host vars as host is not in inventory: %s” % hostname)
ansible.errors.AnsibleError: ERROR! no host vars as host is not in inventory: 10.35.75.247

You don’t show how/where you define self.hostname_hosts.

Here is the self variables. They are read from a settings.yml and are set during execution

self.data = data

self.host = data['host']
self.hostname = data['hostname']
self.conn_name = data['conn_name']
if ipam.ip:
    self.guest_ip4_address = ipam.restart_ip
else:
    self.guest_ip4_address = data['guest_ip4_address']

if ipam.ip:
    self.guest_ip4_address_for_restart = ipam.ip
else:
    self.guest_ip4_address_for_restart = data['guest_ip4_address_for_restart']

if [ipam.gw](http://ipam.gw):
    self.guest_gw4_address = [ipam.gw](http://ipam.gw)
else:
    self.guest_gw4_address = data['guest_gw4_address']

self.template_ip = data['template_ip']

self.host = data['host']
self.hostname_hosts = data['hostname_hosts']
self.hostname_playbook_path = data['hostname_playbook']
self.ip_playbook_path = data['ip_playbook']
self.logger = logger

and at the yml file here is the line:

I realized that i haven’t set the ansible.cfg file path. My cli app is at another path and although i set the inventory variable there, nothing changed. Still not able to connect to the remote host. It is somehow not able to connect, not able to understand the user and password vars defined at the inventory.

It seems that the problem is definetly about reading the inventory. at the /Users/oyarimtepe/Dev/vmware/command-center/cc-cli/venv/lib/python2.7/site-packages/ansible/inventory/init.py

def get_host(self, hostname):
    if hostname not in self._hosts_cache:
        self._hosts_cache[hostname] = self._get_host(hostname)
**..**

**hosts_cache is empty.** 
Thats why it is throwing exception. Seems i am doing something wrong about defining an Inventory as host.

Here is my hosts file /Users/oyarimtepe/Dev/vmware/command-center/register/hosts
[local]
127.0.0.1 ansible_python_interpreter=python

[default]
10.35.75.247 ansible_python_interpreter=python ansible_user=root ansible_ssh_pass=xxxx


I set it at