Site icon New Generation Enterprise Linux

Stop your Ansible dynamic inventory from hammering your API to death

DevOps Tooling On Linux (CI/CD Runners, Ansible)

Stop your Ansible dynamic inventory from hammering your API to death

Technical Briefing | 11/24/2026

You probably have an Ansible playbook running on a cron schedule or triggered by a CI runner that hits your cloud provider API to discover hosts. It works perfectly in development. But then you scale up to a few hundred instances, and suddenly your API calls start hitting rate limits or your runner hangs for thirty seconds just waiting for the inventory plugin to return. I have seen this bring down internal control planes simply because a CI job was too eager.

Caching is not optional for large environments

Ansible inventory plugins have built-in caching support, yet almost no one touches it until it is too late. By default, every time you run a playbook, Ansible asks your cloud provider for the entire list of instances, tags, and private IPs. If you have five playbooks running in parallel, you are essentially DDoSing your own infrastructure metadata service. Enable local caching to keep the inventory results on disk for a set amount of time.

plugin: aws_ec2
cache: yes
cache_plugin: jsonfile
cache_connection: ./inventory_cache
cache_timeout: 300
  • Point your cache_connection to a directory that exists and has correct permissions
  • Set the cache_timeout to something sensible like 300 seconds for development or longer for static environments
  • Delete the cache folder before running a critical deployment if you suspect the cloud state has shifted

The jsonfile plugin is the simplest way to handle this, but you can also use redis if you have multiple runners hitting the same infrastructure. Just make sure your runner environment can actually reach the redis host without latency. If you are still seeing performance issues after caching, double check your inventory plugin filters to ensure you are only pulling the hosts that your playbooks actually need to touch.

Next time your pipeline hangs, check if the inventory process is actually doing useful work or just waiting for a TCP response from an API that has already forgotten who you are. A little cache goes a long way toward keeping your sanity during those 3 AM deployments.

Linux Admin Automation  |  © www.ngelinux.com  |  11/24/2026
0 0 votes
Article Rating
Exit mobile version