On Wed, 10 Jun 2020 22:09:40 -0700 (PDT) utkarsh srivastava <utkarsh.srivastav...@gmail.com> wrote:
> I want to list all variable and it's value defined in hosts file > corresponding to a host > [hostgroup1] > host1 variable1=value1 variable2=value2 variable3=value3 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, ..." . -- Vladimir Botka -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/20200611092318.16dc6ca5%40gmail.com.
pgpno7CdTcid6.pgp
Description: OpenPGP digital signature