How does Ansible inventory work, including groups and group_vars?
⚡
Quick Answer
Inventory lists hosts and groups them; variables can be attached per host (host_vars) or per group (group_vars).
Detailed Answer
Inventory can be static (INI/YAML) or dynamic (plugins that query AWS, GCP, etc.). Groups let you target a subset (hosts: web) and compose meta-groups with :children. group_vars/<group>.yml and host_vars/<host>.yml keep variables next to inventory instead of scattered in playbooks.
Code Example
[web] web1.example.com [production:children] web
💡
Interview Tip
Mention dynamic inventory for cloud environments.
ansibleinventoryvariables