# Dynamic inventory with Azure

**URL:** <https://forum.ansible.com/t/dynamic-inventory-with-azure/32939>\
**Category:** AWX Project\
**Tags:** azure\
**Created:** [May 15, 2020, 11:57am UTC](https://forum.ansible.com/t/dynamic-inventory-with-azure/32939 "2020-05-15T11:57:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sandip\_Khot](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@Sandip\_Khot](https://forum.ansible.com/u/Sandip_Khot)\
**Post date:** [May 15, 2020, 11:57am UTC](https://forum.ansible.com/t/dynamic-inventory-with-azure/32939/1 "2020-05-15T11:57:49Z")

</div>

Hello Team,  
I have created the dynamic inventory and used “Microsoft Azure Resource manager” as a SOURCE.  
My credential section has the below details:

subscription id:  
client id:  
client secret:  
tenant id:

When i sync the inventory it fetches the hosts in that subscription.

My question is : How can i fetch all the hosts which are in different subscription ? in other words how to add multiple subscriptions ?

Thanks  
Sandeep

---

<div class="post-metadata">

**Author:** ![David\_Maple](https://avatars.discourse-cdn.com/v4/letter/d/ad7895/32.png) [@David\_Maple](https://forum.ansible.com/u/David_Maple)\
**Post date:** [May 15, 2020, 12:50pm UTC](https://forum.ansible.com/t/dynamic-inventory-with-azure/32939/2 "2020-05-15T12:50:17Z")

</div>

You can add multiple sources to your inventory, each with its own credentials.

Dave

---

<div class="post-metadata">

**Author:** ![Sandip\_Khot](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@Sandip\_Khot](https://forum.ansible.com/u/Sandip_Khot)\
**Post date:** [May 15, 2020, 2:19pm UTC](https://forum.ansible.com/t/dynamic-inventory-with-azure/32939/3 "2020-05-15T14:19:04Z")

</div>

Thanks for the reply Dave !  
I have one azure account and each customer is deployed in different subscrption in that . If i go with your logic then i have to add the "new source " whenever a new customer is deployed,which is not a best option.

Regards  
Sandeep

---

<div class="post-metadata">

**Author:** ![David\_Maple](https://avatars.discourse-cdn.com/v4/letter/d/ad7895/32.png) [@David\_Maple](https://forum.ansible.com/u/David_Maple)\
**Post date:** [May 15, 2020, 4:25pm UTC](https://forum.ansible.com/t/dynamic-inventory-with-azure/32939/4 "2020-05-15T16:25:02Z")

</div>

Yea, that can get challenging. You might try adding sources directly to the API with a script or playbook.

Dave

---

<div class="post-metadata">

**Author:** ![Adam\_Morris](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@Adam\_Morris](https://forum.ansible.com/u/Adam_Morris)\
**Post date:** [May 16, 2020, 5:44am UTC](https://forum.ansible.com/t/dynamic-inventory-with-azure/32939/5 "2020-05-16T05:44:47Z")

</div>

I looked at improving the azure inventory plugin but the Azure API just isn't designed for it.

Unfortunately I am dealing with almost 200 subscriptions, my solution was a simple python script that talks to azure to get the subscription information and adds a credential and inventory source per subscription.

Updating a single inventory with that many sources times out so I add individual hosts to the appropriate group via API before calling the callback url.

Improvements can be made but this is amazingly easier than trying to create a single tenant inventory plugin using the Azure API.

---

<div class="post-metadata">

**Author:** ![Sandip\_Khot](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@Sandip\_Khot](https://forum.ansible.com/u/Sandip_Khot)\
**Post date:** [May 20, 2020, 9:09am UTC](https://forum.ansible.com/t/dynamic-inventory-with-azure/32939/6 "2020-05-20T09:09:18Z")

</div>

Hello Adam,

Would you mind sharing the python script you are using ?  
Atleast a sniffet of it and i can modify or improvise it.

Regards  
sandeep
