diff --git a/ansible/roles/rabbitmq/tasks/config.yml b/ansible/roles/rabbitmq/tasks/config.yml index fd7fd707eb..b8fed458c6 100644 --- a/ansible/roles/rabbitmq/tasks/config.yml +++ b/ansible/roles/rabbitmq/tasks/config.yml @@ -79,6 +79,24 @@ notify: - Restart rabbitmq container +- name: Copying over advanced.config + become: true + vars: + service: "{{ rabbitmq_services['rabbitmq'] }}" + template: + src: "{{ item }}" + dest: "{{ node_config_directory }}/{{ project_name }}/advanced.config" + mode: "0660" + with_first_found: + - "{{ node_custom_config }}/rabbitmq/{{ inventory_hostname }}/advanced.config" + - "{{ node_custom_config }}/rabbitmq/advanced.config" + - "advanced.config.j2" + when: + - inventory_hostname in groups[service.group] + - service.enabled | bool + notify: + - Restart rabbitmq container + - name: Copying over definitions.json become: true vars: diff --git a/ansible/roles/rabbitmq/templates/advanced.config.j2 b/ansible/roles/rabbitmq/templates/advanced.config.j2 new file mode 100644 index 0000000000..d83b6742af --- /dev/null +++ b/ansible/roles/rabbitmq/templates/advanced.config.j2 @@ -0,0 +1,7 @@ +[ + {kernel, [ + {inet_dist_use_interface, {% raw %}{{% endraw %}{{ api_interface_address | put_address_in_context('rabbitmq') }}}}, + {inet_dist_listen_min, {{ role_rabbitmq_cluster_port }}}, + {inet_dist_listen_max, {{ role_rabbitmq_cluster_port }}} + ]} +]. diff --git a/ansible/roles/rabbitmq/templates/rabbitmq.json.j2 b/ansible/roles/rabbitmq/templates/rabbitmq.json.j2 index 8f72100bdf..150b1355d1 100644 --- a/ansible/roles/rabbitmq/templates/rabbitmq.json.j2 +++ b/ansible/roles/rabbitmq/templates/rabbitmq.json.j2 @@ -19,6 +19,12 @@ "owner": "rabbitmq", "perm": "0600" }, + { + "source": "{{ container_config_directory }}/advanced.config", + "dest": "/etc/rabbitmq/advanced.config", + "owner": "rabbitmq", + "perm": "0600" + }, { "source": "{{ container_config_directory }}/definitions.json", "dest": "/etc/rabbitmq/definitions.json", diff --git a/kolla_ansible/put_address_in_context.py b/kolla_ansible/put_address_in_context.py index d176a5611b..69355283f8 100644 --- a/kolla_ansible/put_address_in_context.py +++ b/kolla_ansible/put_address_in_context.py @@ -14,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from ipaddress import ip_address from kolla_ansible.exception import FilterError @@ -27,18 +28,32 @@ def put_address_in_context(address, context): :returns: string with address in proper context """ - if context not in ['url', 'memcache']: + if context not in ['url', 'memcache', 'rabbitmq']: raise FilterError("Unknown context '{context}'" .format(context=context)) - if ':' not in address: + if ':' not in address and context != 'rabbitmq': return address # must be IPv6 raw address if context == 'url': return '[{address}]'.format(address=address) - elif context == 'memcache': + if context == 'memcache': return 'inet6:[{address}]'.format(address=address) + # rabbitmq/erlang has special syntax for ip addresses in IPv4 and IPv6 + # see: https://www.erlang.org/doc/man/inet.html + # replacing dots and colons with decimal points + # and converting IPv6 as described here: + # https://www.erlang.org/doc/man/inet.html#type-ip6_address + + if context == 'rabbitmq': + if ip_address(address).version == 6: + return (",".join(['16#%x' % int(x, 16) + for x in + ip_address(address).exploded.split(':')])) + + return address.replace('.', ',') + return address diff --git a/kolla_ansible/tests/unit/test_address_filters.py b/kolla_ansible/tests/unit/test_address_filters.py index 338afb1301..be2cee78d9 100644 --- a/kolla_ansible/tests/unit/test_address_filters.py +++ b/kolla_ansible/tests/unit/test_address_filters.py @@ -51,6 +51,15 @@ class TestAddressContextFilter(unittest.TestCase): self.assertEqual(put_address_in_context(addr, context), 'inet6:[{}]'.format(addr)) + def test_rabbitmq_context(self): + context = 'rabbitmq' + addr = '192.168.1.1' + self.assertEqual(put_address_in_context(addr, context), + '192,168,1,1') + addr = 'fd::' + self.assertEqual(put_address_in_context(addr, context), + '16#fd,16#0,16#0,16#0,16#0,16#0,16#0,16#0') + def test_unknown_context(self): self.assertRaises(FilterError, put_address_in_context, '', 'lol') diff --git a/releasenotes/notes/fix-rabbitmq-interface-configuration-b39c954fb8763d9c.yaml b/releasenotes/notes/fix-rabbitmq-interface-configuration-b39c954fb8763d9c.yaml new file mode 100644 index 0000000000..3dab5c6dee --- /dev/null +++ b/releasenotes/notes/fix-rabbitmq-interface-configuration-b39c954fb8763d9c.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + adds back the option to configure the rabbitmq + clustering interface via kolla + `LP#1900160 `