# Some problem when using  Dynamic Inventory Sources and python API

**URL:** <https://forum.ansible.com/t/some-problem-when-using-dynamic-inventory-sources-and-python-api/21810>\
**Category:** Ansible Project\
**Created:** [June 19, 2016, 7:16am UTC](https://forum.ansible.com/t/some-problem-when-using-dynamic-inventory-sources-and-python-api/21810 "2016-06-19T07:16:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Young\_Yang](https://avatars.discourse-cdn.com/v4/letter/y/ecb155/32.png) [@Young\_Yang](https://forum.ansible.com/u/Young_Yang)\
**Post date:** [June 19, 2016, 7:16am UTC](https://forum.ansible.com/t/some-problem-when-using-dynamic-inventory-sources-and-python-api/21810/1 "2016-06-19T07:16:02Z")

</div>

Hi,  
I’m developing a script using ansible python API ([http://docs.ansible.com/ansible/developing\_api.html](http://docs.ansible.com/ansible/developing_api.html))  
Here is my ansible version

```auto

ansible 2.2.0 (devel af150ea43a) last updated 2016/06/18 02:00:10 (GMT +800)
lib/ansible/modules/core: (detached HEAD f0f5272f90) last updated 2016/06/19 09:59:32 (GMT +800)
lib/ansible/modules/extras: (detached HEAD 6cb6829384) last updated 2016/06/19 09:59:53 (GMT +800)
config file =
configured module search path = Default w/o overrides

```

My inventory is dynamic, so I follow the guide here : [http://docs.ansible.com/ansible/developing\_inventory.html](http://docs.ansible.com/ansible/developing_inventory.html)

I found my script must support the `--list` option and `--host <hostname>` option.  
What stumbles me is that when I use `--host <hostname>`, the `<hostname>` must appear in the output of the --list option.  
But I can’t get all the hosts that I have access in advance. I just render my options with `<hostname>` when I call the `--host <hostname>` option.

Actually, all I need is to render my connection options based on the `<hostname>` option and I can’t know the list of in advance.  
How can I achieve this goal?

Thanks in advance 🙂
