Find out where variable was defined

Hi,

I’am using Ansible 2.8.6.

Is there a posibility to find out, where a variable was defined?

I want to check inside a role if the variable was defined under the defaults folder or higher in the priority.

https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable

If the variable is in the default state, I want to promt the message “Are you sure you want to use the role default variable?” and the user must confirm.

Thanks for your help
Alexander

I'm not aware of such information being available. But the use-case can be
easily achieved by including role's defaults into a dictionary and comparing
the variable. For example

  $ cat roles/role1/tasks/main.yml
  - include_vars:
      file: "{{ role_path }}/defaults/main.yml"
      name: "defaults"
  - block:
      - pause:
          prompt: "Are you sure you want to use the role default variable?"
          echo: yes
        register: result
      - debug:
          var: result.user_input
    when: var1 == defaults.var1

Cheers,

  -vlado

Great idea. Thanks for your help.