How do you make dynamic inventory fast with many instances?
IntermediateProductionPerformance and Scale
Answer
- Filter at the API (
filters:andregions:) instead of fetching everything and discarding it client-side. - Enable plugin caching (
cache: true,cache_timeout) so repeated runs andansible-inventorycalls do not call the EC2 API each time. - Avoid expensive
composeexpressions and unusedhostnamesstrategies. - In AWX, use inventory sources with "update on launch" and a cache timeout, or schedule syncs separately from jobs.
plugin: amazon.aws.aws_ec2
regions: [ap-south-1]
filters:
tag:Managed: ansible
instance-state-name: running
cache: true
cache_timeout: 300
More on Performance and Scale
Why can Ansible be slower than a shell script for 100 servers, and what dominates the time?BeginnerHow do you choose the `forks` value?BeginnerWhat is SSH pipelining and why does it help?BeginnerWhich SSH settings matter for performance and stability?IntermediateHow do you find out which tasks are slow?BeginnerHow do you reduce the cost of fact gathering?Intermediate