# using multiple dynamic inventory scripts at once

**URL:** <https://forum.ansible.com/t/using-multiple-dynamic-inventory-scripts-at-once/17018>\
**Category:** Ansible Project\
**Created:** [December 10, 2014, 10:48pm UTC](https://forum.ansible.com/t/using-multiple-dynamic-inventory-scripts-at-once/17018 "2014-12-10T22:48:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Florin\_Andrei](https://avatars.discourse-cdn.com/v4/letter/f/c77e96/32.png) [@Florin\_Andrei](https://forum.ansible.com/u/Florin_Andrei)\
**Post date:** [December 10, 2014, 10:48pm UTC](https://forum.ansible.com/t/using-multiple-dynamic-inventory-scripts-at-once/17018/1 "2014-12-10T22:48:46Z")

</div>

New to Ansible, just testing it. For now, I’m using dynamic inventory scrips, and I’m trying to run simple commands on all hosts, via ansible.

I’ve setup ec2.py and digital\_ocean.py in ~/ansible/, and both scripts work just fine. Provisioned with the correct credentials, if I run either script manually, I get the correct list of assets from those two cloud providers, respectively.

If I run Ansible with just one script (either ec2.py or digital\_ocean.py) then that also works well:

ansible -i ~/ansible/ec2.py -u my-special-user -f 20 -s \* -m shell -a ‘ps’

ansible -i ~/ansible/digital\_ocean.py -u my-special-user -f 20 -s \* -m shell -a ‘ps’

But if I try to do just -i ~/ansible/ (hoping to use both inventory scripts in a concatenated list) then it doesn’t work. Spying the process list with pstree, I’ve noticed that ansible runs digital\_ocean.py --host with all the hosts from the EC2 list. That can’t be right. No wonder it doesn’t work then.

What is the correct way to use several dynamic inventory scripts at once for something simple like -m shell -a ‘ps’?

P.S.:

If I run ./digital\_ocean.py --list manually, it just throws a JSON with my hosts. But if I do ./ec2.py --list manually, then it generates first the “\_meta”: tag, and then throws a list similar to the DO script. Not sure if this is relevant to the main issue, I just thought I should mention it.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [December 10, 2014, 10:54pm UTC](https://forum.ansible.com/t/using-multiple-dynamic-inventory-scripts-at-once/17018/2 "2014-12-10T22:54:21Z")

</div>

Ansible supports inventory directories. If you place both ec2.py and digital\_ocean.py in a directory called “inventory”, you could then use:

ansible -i ~/ansible/inventory -u my-special-user -f 20 -s \* -m shell -a ‘ps’

You could then also call each inventory script separately if you needed.

---

<div class="post-metadata">

**Author:** ![Florin\_Andrei](https://avatars.discourse-cdn.com/v4/letter/f/c77e96/32.png) [@Florin\_Andrei](https://forum.ansible.com/u/Florin_Andrei)\
**Post date:** [December 10, 2014, 11:27pm UTC](https://forum.ansible.com/t/using-multiple-dynamic-inventory-scripts-at-once/17018/3 "2014-12-10T23:27:59Z")

</div>

Okay, I placed both inventory scripts in ~/ansible/inventory and it works. The command opens an ssh connection to each host on both clouds.

But, again, spying the process tree list while ansible is running, I’ve noticed something odd. (BTW, all runs are done after clearing the caches for both inventory scripts every time)

If I do -i ~/ansible/inventory/ec2.py, I see ansible running ec2.py --list for a while, then it initiates the ssh connections.

If I do -i ~/ansible/inventory/digital\_ocean.py, I see ansible running digital\_ocean.py --list for a while, then digital\_ocean.py --host once for each host I have at DO, and then it launches the ssh connections.

But if I do -i ~/ansible/inventory, I see this: It runs one of the scripts with --list; it runs the other script with --list; then it runs digital-ocean.py --host **for all hosts in both lists** (EC2 and DO)! This is A) unnecessary, B) slow, and C) hammering the DO API servers for no good reason.

Is it a bug, or am I still doing something wrong?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [December 11, 2014, 5:14am UTC](https://forum.ansible.com/t/using-multiple-dynamic-inventory-scripts-at-once/17018/4 "2014-12-11T05:14:30Z")

</div>

this is dependent on implementation of the inventory scripts, they can  
return all host information with --list, if they do not ansible has to  
call them per host also.
