How does inventory caching work and when would you enable it?

AdvancedConceptInventory
Answer

Dynamic inventory plugins can cache the API response so each run does not re-query the cloud, which matters with thousands of instances or API throttling.

plugin: amazon.aws.aws_ec2
regions: [ap-south-1]
cache: true
cache_plugin: ansible.builtin.jsonfile
cache_connection: /tmp/aws_inventory_cache
cache_timeout: 600

The trade-off is stale data: a new instance will not show up until the cache expires. Force a refresh with ansible-inventory --flush-cache (or by deleting the cache dir). Cache TTL should be shorter than your autoscaling churn.

All Ansible questions Roadmap: Ansible

More on Inventory