{%- set ns = namespace(first_host="") %}
[
  {version, 1},
  {nodes, [
  {% for host in groups[role_rabbitmq_groups]|sort %}
    {'rabbit@{{ hostvars[host]['ansible_hostname'] }}', disc}
      {%- if loop.first -%} {%- set ns.first_host = host -%} {%- endif -%}
      {%- if not loop.last -%},{%- endif %}
  {% endfor %}
  ]},
  {gospel,
    {node, 'rabbit@{{ hostvars[ns.first_host]['ansible_hostname'] }}'}}
].

Add a code snippet to your website: www.paste.org