I see what you want, but it isn't possible. From each host's perspective, the `group_comment` variable will have the value as set in whichever one of that host's groups where the group name sorts last, as that's the last one loaded. So it is consistent, just not a solution to your problem.
You can work around it if you want to go to the trouble. Say you have groups named gr1, gr2, gr3, etc. Within each group, put that group's comment in a variable called `group_comment_<group_name>`, i.e. `group_comment_gr1`, `group_comment_gr2`, `group_comment_gr3`, etc.
Then do something like the following to create a `group_comments` list for each host.
- name: Create a list of group_comment_* variable names
ansible.builtin.set_fact:
# Two different ways to do it.
group_comment_names_a: "{{ ['group_comment_'] | product(vars.group_names) | map('join') | flatten }}"
group_comment_names_b: "{{ query('ansible.builtin.varnames', '^group_comment_.+') }}"
- name: Join group_comment_* into a list
ansible.builtin.set_fact:
group_comments: |
{% set gclist = [] %}
{% for gcn in group_comment_names_a %}
{% set _ = gclist.append(query('ansible.builtin.vars', gcn)) %}
{% endfor %}{{ gclist | flatten }}
I tried lots of different ways to invoke `ansible.builtin.vars` on a list using "normal" jinja pipelines before resorting to the old-school for loop above. If somebody knows how to do it I'd love to see your solution.
Anyway, you end up with each host having a list containing each comment from each of its groups. But I somehow doubt that solves your problem either. It's still a host-centric view of your group comments.