From 1b2fd2cb5ffd8c7b909ac178f81f764669dc49d8 Mon Sep 17 00:00:00 2001 From: John Imison <857198+Im0@users.noreply.github.com> Date: Thu, 12 Sep 2019 04:29:05 +1000 Subject: [PATCH] rabbitmq_publish fix for incorrectly stating message was not published to the queue (#61960) * Pika v1.0.0 and above were causing issues for publish_message. Updated to ensure publish_message works with pika 0.13.1 and 1.0.0 and above. * Adding changelog fragment for rabbitmq_publish fix. * Updating return value. --- ...55919-rabbitmq_publish-fix-for-recent-pika-versions.yml | 2 ++ lib/ansible/module_utils/rabbitmq.py | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/55919-rabbitmq_publish-fix-for-recent-pika-versions.yml diff --git a/changelogs/fragments/55919-rabbitmq_publish-fix-for-recent-pika-versions.yml b/changelogs/fragments/55919-rabbitmq_publish-fix-for-recent-pika-versions.yml new file mode 100644 index 0000000000..8175c1e9fc --- /dev/null +++ b/changelogs/fragments/55919-rabbitmq_publish-fix-for-recent-pika-versions.yml @@ -0,0 +1,2 @@ +bugfixes: + - rabbitmq_publish - Fix to ensure the module works correctly for pika v1.0.0 and later. (https://github.com/ansible/ansible/pull/61960) diff --git a/lib/ansible/module_utils/rabbitmq.py b/lib/ansible/module_utils/rabbitmq.py index 718fcf19d2..aabb8a235b 100644 --- a/lib/ansible/module_utils/rabbitmq.py +++ b/lib/ansible/module_utils/rabbitmq.py @@ -18,6 +18,7 @@ import traceback PIKA_IMP_ERR = None try: import pika + import pika.exceptions from pika import spec HAS_PIKA = True except ImportError: @@ -193,4 +194,8 @@ class RabbitClient(): if args['exchange'] is None: args['exchange'] = '' - return self.conn_channel.basic_publish(**args) + try: + self.conn_channel.basic_publish(**args) + return True + except pika.exceptions.UnroutableError: + return False