Using group vars and vars from vars prompt

I am trying to get a value through vars prompt in my playbook and writing a task in a role to see if the value == foo or if value == bar
if the value == foo ,i want to get values from the vars.yaml file which has a section for foo .
The section for foo in vars.yaml file has source path and destination path for copying.

I am struggling to see how to use loops in this case,any help is appreciated.

Can you try something like this

- name: Conditionally decide to load in variables into 'plans' when x is 0, otherwise do not. (2.2)
  include_vars:
    file: contingency_plan.yaml
    name: plans
  when: x == 0