DevOps / Ansible Interview questions
When would you choose dynamic inventory over static inventory?
A static inventory file is fine when the set of managed hosts is small and changes rarely, since manually editing a text file is simple in that case. Dynamic inventory becomes valuable once hosts are created and destroyed frequently, such as in an auto-scaling cloud environment, where a static list would constantly go stale.
# aws_ec2 dynamic inventory plugin example plugin: amazon.aws.aws_ec2 regions: - us-east-1 filters: tag:Environment: production
Dynamic inventory plugins query a live source, cloud provider APIs (AWS, Azure, GCP), a CMDB, or container orchestration platforms, at run time, and can group hosts automatically by attributes like tags, region, or instance type. This is the right choice whenever the "truth" about which hosts exist and their properties already lives somewhere else in the infrastructure, since keeping a static file manually in sync with that source is both extra work and a source of drift the moment someone forgets to update it.
More Related questions...