From 12c37802e84bfa6602ed0dc39bb63f2a203aaac7 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Wed, 19 Dec 2018 14:30:41 +0100 Subject: [PATCH] rabbitmq_binding: Fix using empty routing key (#48597) * rabbitmq_binding: Fix using empty routing key If the routing key is an empty string we need to use the special props value ~ in the URL. Otherwise the last part of the URL will be empty, which will instead be equivalent to the "list all bindings" API call which always returns 200 OK (as long as the exchange and queue exists). * rabbitmq_binding: Move routing_key test outside format Test the routing_key value and set the props value outside the format call. We leave the original routing_key untouched since its original value is later needed in create(). --- lib/ansible/modules/messaging/rabbitmq/rabbitmq_binding.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/messaging/rabbitmq/rabbitmq_binding.py b/lib/ansible/modules/messaging/rabbitmq/rabbitmq_binding.py index e3f44adea9..87c56bf210 100644 --- a/lib/ansible/modules/messaging/rabbitmq/rabbitmq_binding.py +++ b/lib/ansible/modules/messaging/rabbitmq/rabbitmq_binding.py @@ -108,6 +108,7 @@ class RabbitMqBinding(object): self.verify = self.module.params['cacert'] self.cert = self.module.params['cert'] self.key = self.module.params['key'] + self.props = urllib_parse.quote(self.routing_key) if self.routing_key != '' else '~' self.base_url = '{0}://{1}:{2}/api/bindings'.format(self.login_protocol, self.login_host, self.login_port) @@ -116,7 +117,7 @@ class RabbitMqBinding(object): urllib_parse.quote(self.name, safe=''), self.destination_type, urllib_parse.quote(self.destination, safe=''), - urllib_parse.quote(self.routing_key)) + self.props) self.result = { 'changed': False, 'name': self.module.params['name'],