Variable node address

This adds a var similar to what we have in the galera_server role [1],
making the local node's incoming address a var. This allows the
role's consumer to define a different node address than the one used
by ansible in ansible_host.

[1] https://github.com/openstack/openstack-ansible-galera_server/blob/master/defaults/main.yml#L92

Change-Id: I30e51668545095c8f6d91902516767d7bf158202
This commit is contained in:
Logan V 2018-06-05 08:37:40 -05:00
parent 0bda3a7453
commit b56ff9d141
2 changed files with 21 additions and 2 deletions

View File

@ -23,6 +23,25 @@ rabbitmq_package_state: "latest"
# Inventory group containing the hosts for the cluster
rabbitmq_host_group: "rabbitmq_all"
# The local address used for the rabbitmq cluster node
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_primary_cluster_node: "{{ hostvars[groups[rabbitmq_host_group][0]]['ansible_hostname'] }}"
# Upgrading the RabbitMQ package requires shutting down the cluster. This variable makes upgrading

View File

@ -34,8 +34,8 @@
lineinfile:
dest: /etc/hosts
state: present
line: "{{ hostvars[item]['ansible_host'] }} {{ hostvars[item]['ansible_hostname'] }} {{ hostvars[item]['ansible_hostname'].split('.')[0] }}"
with_items: "{{ groups[rabbitmq_host_group] }}"
line: "{{ item.address }} {{ item.hostnames | join(' ') }}"
with_items: "{{ rabbitmq_hosts_entries }}"
tags:
- rabbitmq-config