Azure dynamic inventory very slow to load

We are using ansible with the azure dynamic inventory plugin 3.3.1. Our ansible version is 2.18.x. It works, and loads our keyed groups fine, but it takes a really long time to query. For example it takes about 1 minute and 40 seconds to load the inventory in turn making it very difficult to work with. Our inventory is not that big, we only have about a 75 or so VMs in virtual machine scale sets.

Hi @wes ,

We had some slow loading in the past to the point that the sync would timeout. Our research showed that by default, the Azure dynamic inventory plugin uses a batch fetch model that attempts to retrieve multiple hosts before processing. This can be disabled to use the traditional serial fetch method. You can add the following to your source variables

batch_fetch: false

If that helps, you can try reverting back and tweaking the batch fetch settings to see if you get better results but I can say that we’ve had batch fetch disabled for a couple years now and it’s been stable. Our inventory is around 150-200 VMs.

azure.azcollection.azure_rm inventory – Azure Resource Manager inventory plugin — Ansible Community Documentation

Best regards,

Joe

Thanks @iwt-cmd . That speeds it up quite a bit. Instead of 1m40s I can now query the azure inventory in about 45s. The 45s still seems slow though. For example if someone is using ansible for basic linux orchestration tasks then they would expect it to load within seconds.

Is there any way to speed it up further? I noticed there is some feature called “cache”? I tried setting that to true but it didn’t seem to do anything.

I ended up adding settings like this to cache the inventory:

cache: true
cache_plugin: ansible.builtin.jsonfile
cache_timeout: 7200
cache_connection: /tmp/azure_inventory

This seems to work quite a bit better since it’s just referencing the local cache, until it expires. So I think what we will do if we have any playbooks that require a current inventory, we will just run --flush-cache / invalidate the cache during run.

1 Like

Great find! We kind of wrote off the sync time to the nature of the Azure API and the number of systems we were pulling but would be awesome to make that faster.

Best regards,

Joe