There is no method, function, lookup plugin, special variable, etc. to find out where a variable comes from. Without knowing the run-string you also can't tell whether extra variables are used or not.
The simplest method to determine whether extra variables are used might be based on the fact that extra vars are the highest precedence. For example, test if extra vars overrode a variable
shell> cat input_vars.yml
extra_vars: true
var1: foo
var2: bar
Declare the variable extra_vars also in the playbook
shell> cat test.yml
- hosts: localhost
vars:
extra_vars: false
tasks:
- assert:
that: extra_vars|bool
fail_msg: Extra vars missing. End of play.
- debug:
msg: |
var1: {{ var1 }}
var2: {{ var2 }}
The playbook fails if you run it without extra vars
shell> ansible-playbook test.yml
PLAY [localhost] *****************************************************************************
TASK [assert] ********************************************************************************
fatal: [localhost]: FAILED! => changed=false
assertion: extra_vars|bool
evaluated_to: false
msg: Extra vars missing. End of play.
The playbook will continue if extra vars are used
shell> ansible-playbook test.yml -e@input_vars.yml
PLAY [localhost] *****************************************************************************
TASK [assert] ********************************************************************************
ok: [localhost] => changed=false
msg: All assertions passed
TASK [debug] *********************************************************************************
ok: [localhost] =>
msg: |-
var1: foo
var2: bar