Use hosts from groups within variable files

is it possible to access a host of a group from within a variable file (like Ansible does in Templates?)

here is the what i am trying to do:

That shouldn’t be a problem. This example lists the ip address of the first node in the “db” group, for instance:

  • name: Print a variable from inventory (different hostgroup)
    hosts: all
    tasks:
  • debug:
    msg: “{{ hostvars[groups[‘db’][0]][‘ansible_default_ipv4’][‘address’] }}”

thanks for the quick response.

the example you gave is using a Playbook, what i am talking about it using this syntax within a variables file

never mind was able to make it work: