From f3978e22c20eebfd2e730b747b336b948ce9d966 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Evrard Date: Thu, 12 Jul 2018 13:16:43 +0200 Subject: [PATCH] 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 --- defaults/main.yml | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index b0f9f694..1b39a5ed 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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'] }}"