% {{ ansible_managed }}

{% if RABBITMQ_CLUSTERED -%}
  {%- set hosts= [] -%}

  {%- for host in hostvars.keys() -%}
    {% do hosts.append("rabbit@ip-" + host.replace('.','-')) %}
  {%- endfor %}

[{rabbit,
  [{cluster_nodes, {['{{ hosts|join("\',\'") }}'], disc}}]}].

{%- else -%}
{# If rabbitmq_clustered_hosts is set, use that instead assuming an aws stack.
   Note: That these names should include the node name prefix. eg. 'rabbit@hostname'
#}
[{rabbit,
  [{cluster_nodes, {['{{ rabbitmq_clustered_hosts|join("\',\'") }}'], disc}}]}].

{%- endif -%}
