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.
More on Inventory
What is an inventory and why does Ansible need one?BeginnerWhat are the INI and YAML inventory formats and how do they differ?BeginnerHow do you create groups of groups?BeginnerExplain host patterns: `:`, `:&`, `:!` and wildcards.IntermediateWhich connection variables can you set per host in inventory?BeginnerWhat are `group_vars` and `host_vars` directories?Intermediate