Is this what you're looking for?
$ cat groupvars-inventory.ini
[test]
test1 ansible_host=1.1.1.1
test2 ansible_host=2.2.2.2
[dev]
dev1 ansible_host=3.3.3.3
dev2 ansible_host=4.4.4.4
$ cat groupvars.yml
---
- name: Demo for accessing inventory group variables
# ansible-playbook groupvars.yml -i ./groupvars-inventory.ini -v
hosts: localhost
tasks:
- name: Gather the ansible_host values from hosts in the test group
set_fact:
test_ips: |
{%- set ip=[] -%}
{%- for h in groups['test'] -%}
{%- set _ = ip.append(hostvars[h]['ansible_host']) -%}
{%- endfor %}{{ ip }}
# TASK [Gather the ansible_host values from hosts in the test group] ****
# ok: [localhost] => changed=false
# ansible_facts:
# test_ips:
# - 1.1.1.1
# - 2.2.2.2
- name: Same thing but with legit filters in the dev group
set_fact:
dev_ips: "{{ groups['dev']|map('extract',hostvars,'ansible_host') }}"
# TASK [Same thing but with legit filters in the dev group] ****
# ok: [localhost] => changed=false
# ansible_facts:
# dev_ips:
# - 3.3.3.3
# - 4.4.4.4