You might improve the situation with name-spacing of the variables, e.g
create unique prefix which can be used to filter variables.
But, this is not solving your problem. IMHO, it's not possible to tell from
which precedence's level variable comes from
https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable
Instead, if really needed, as a hint, it might be possible to select variables
defined by user. For example, as a first step, remove ansible_facts_* from
hostvars
- hosts: all
tasks:
- set_fact:
my_facts_keys: "{{ ansible_facts.keys()|
map('regex_replace', my_regex, my_replace)|
list }}"
vars:
my_regex: '^(.*)$'
my_replace: 'ansible_\1'
- set_fact:
my_hostvar_keys: "{{ hostvars[inventory_hostname].keys()|
list }}"
- debug:
msg: "{{ my_hostvar_keys|
difference(my_facts_keys)|
sort }}"
gives
"msg": [
"ansible_check_mode",
"ansible_diff_mode",
"ansible_facts",
"ansible_forks",
"ansible_inventory_sources",
"ansible_local",
"ansible_perl_interpreter",
"ansible_playbook_python",
"ansible_python_interpreter",
"ansible_run_tags",
"ansible_skip_tags",
"ansible_verbosity",
"ansible_version",
"gather_subset",
"group_names",
"groups",
"inventory_dir",
"inventory_file",
"inventory_hostname",
"inventory_hostname_short",
"module_setup",
"my_facts_keys",
"omit",
"playbook_dir",
"var1",
"var2",
"var3"
]
This is a list of user-defined variables plus Ansible "special variables"
https://docs.ansible.com/ansible/latest/reference_appendices/special_variables.html#special-variables
If you want to proceed this way create and subtract the list of special
variables (I don't know how to automate this), and fine-tune the list
"ansible_facts, module_setup, ..." .