Interview Prep/Ansible/Variables, Facts and Templates

You need different values per environment without copying playbooks.

BeginnerScenarioVariables, Facts and Templates
Answer

Situation read → One code, many configurations.

What I'd do → One inventory per environment, each with group_vars/all.yml and group files.

inventories/
  staging/group_vars/all.yml   # app_replicas: 2
  prod/group_vars/all.yml      # app_replicas: 6

Run ansible-playbook -i inventories/prod site.yml.

Why → Environment data lives with the inventory; the playbook stays generic.

Interview tip → Avoid if env == 'prod' branches in tasks; use variables.

All Ansible questions Roadmap: Ansible

More on Variables, Facts and Templates