Cleanup generation of rabbitmq server data

In the past, ansible_hostname could contain a FQDN or a hostname.
This is not the case anymore as fqdns are now stored in facts as
ansible_fqdn while short hostnames are stored in ansible_hostname.

This also simplifies the reading by using json_query.

Change-Id: I0755684846e42b4a17c4e46d70940535daaf73e7
This commit is contained in:
Jean-Philippe Evrard 2018-07-12 13:16:43 +02:00
parent 2239fb14f6
commit f3978e22c2

View File

@ -28,19 +28,12 @@ rabbitmq_node_address: "{{ ansible_host }}"
# Hosts file entries (set this to an empty list to disable /etc/hosts generation
# for the rabbitmq cluster nodes)
rabbitmq_hosts_entries: |-
{% set _var = [] %}
{% for cluster_host in groups[rabbitmq_host_group] %}
{% set _addr = hostvars[cluster_host]['rabbitmq_node_address'] |
default(hostvars[cluster_host]['ansible_host']) %}
{% set _hostnames = [
hostvars[cluster_host]['ansible_hostname'],
hostvars[cluster_host]['ansible_hostname'].split('.')[0]
]
%}
{% set _ = _var.append({'address': _addr, 'hostnames': _hostnames}) %}
{% endfor %}
{{ _var }}
rabbitmq_hosts_entries: >-
{{ groups[rabbitmq_host_group] | map('extract', hostvars) | list |
json_query(
"[].{address: rabbitmq_node_address || ansible_host , hostnames: [ansible_hostname, ansible_fqdn] }"
)
}}
rabbitmq_primary_cluster_node: "{{ hostvars[groups[rabbitmq_host_group][0]]['ansible_hostname'] }}"