Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

In rabbitmq_policy, tags values that should be ints are passed in a strings #1308

Closed
dwcramer opened this issue Nov 30, 2015 · 12 comments
Closed

Comments

@dwcramer
Copy link

dwcramer commented Nov 30, 2015

ISSUE TYPE

Bug Report

COMPONENT NAME

rabbitmq_policy module

ANSIBLE VERSION

N/A

SUMMARY

I worked around the bug described below (the original report was from a colleague) with the following hack:

diff --git a/ops/library/rabbitmq_policy.py b/ops/library/rabbitmq_policy.py
index 81d7068..dd81c56 100644
--- a/ops/library/rabbitmq_policy.py
+++ b/ops/library/rabbitmq_policy.py
@@ -134,6 +134,13 @@ def main():
         supports_check_mode=True
     )

+    # HACK: Convert any items in tags to ints if we can
+    for key, value in module.params['tags'].iteritems():
+        try:
+            module.params['tags'][key] = int(value)
+        except ValueError:
+            pass
+
     name = module.params['name']
     state = module.params['state']
     rabbitmq_policy = RabbitMqPolicy(module, name)

I can set the max-length-bytes for a rabbitmq_policy as follows:

- name: Set size limit and dead-letter exchange for "high-priority" queue
  rabbitmq_policy:
    name: "high-priority"
    pattern: "^high-priority$"
    tags:
      "max-length-bytes": 10000000000
      "dead-letter-exchange": "purged"

where max-length-bytes is set to a literal number. This works fine. But I need to replace the literal with a variable like this:

"max-length-bytes": {{ rabbit_queue_normal_priority_max_bytes }}

where of course the value of rabbit_queue_normal_priority_max_bytes comes from an inventory, where it is an unquoted number literal. When I run the playbook I get this error:

ERROR: Syntax Error while loading YAML script, /Users/ericevan/projects/dsx-fanuc/ops/roles/configure-rabbit/tasks/main.yml
Note: The error may actually appear before this position: line 9, column 28

    tags:
      "max-length-bytes": {{ rabbit_queue_high_priority_max_bytes }}
                           ^
We could be wrong, but this one looks like it might be an issue with
missing quotes.  Always quote template expression brackets when they
start a value. For instance: . . .

So I put quotes around it:

"max-length-bytes": "{{ rabbit_queue_normal_priority_max_bytes }}"

and then I get this error:

failed: [ericevan-dev-satellite.xbudev.org] => {"cmd": "/usr/sbin/rabbitmqctl -q -n rabbit set_policy -p / high-priority '^high-priority$' '{\"max-length-bytes\": \"1000000000\", \"dead-letter-exchange\": \"purged\"}' --priority 0", "failed": true, "rc": 2}
stderr: Error: Validation failed

<<"1000000000">> is not a valid maximum length in bytes

I.e., it interpreted the value as a quoted string. Googling around, I find that you are supposed to cast the variable to its type; e.g.:

"max-length-bytes": "{{ rabbit_queue_normal_priority_max_bytes | int }}"

but this resulted in exactly the same error as above. There are some posts saying that this was a problem in an earlier Ansible release, but see also ansible/ansible#5463

@robynbergeron
Copy link
Contributor

[module: messaging/rabbitmq_policy.py]

@robynbergeron
Copy link
Contributor

@dwcramer -- Thanks for submitting this bug report.

@retr0h -- thanks in advance for taking a look at this bug report and for your ongoing work in maintaining this module.

@ansibot
Copy link

ansibot commented Aug 4, 2016

@retr0h, ping. This issue is still waiting on your response.
click here for bot help

@pmozdzynski
Copy link

pmozdzynski commented Sep 7, 2016

Hi.

This is fixed. have a look at the below ansible setup :

 - name: set the policy 
  rabbitmq_policy:
    name={{ item.name }}
    vhost={{ item.vhost | default('/', false) }}
    pattern={{ item.pattern }}
    tags={{ item.tags }}
    priority={{ item.priority }}
  with_items: rabbitmq_policy_configuration

-------------------------------------------------------------------------------------------------------------------
#so on the yaml:

rabbitmq_policy_configuration:
- name: HA
    vhost: virtualhost1
    pattern: "datapump(.*)"
    priority: 1
    tags:
      ha-mode: all
      max-length-bytes: 5368709120

What you need is the latest rabbitmq-server that support rabbitmqctl set_policy for the "max-length-bytes" . If you can set this from the command line , than my above sample will work for you.
I faced mentioned above errors with rabbitmq-server-3.3.5-23 . When I upgraded rabbitmq-server to 3.6 all started working again.
You need to also avoid the string in the tags , so int parameter will be parsed. Just use my sample above for testing.

@ansibot
Copy link

ansibot commented Sep 7, 2016

@retr0h, ping. This issue is still waiting on your response.
click here for bot help

@ansibot
Copy link

ansibot commented Oct 6, 2016

@retr0h, ping. This issue is still waiting on your response.
click here for bot help

@pmozdzynski
Copy link

no longer an issue.

@ansibot
Copy link

ansibot commented Oct 22, 2016

@retr0h, ping. This issue is still waiting on your response.
click here for bot help

1 similar comment
@ansibot
Copy link

ansibot commented Nov 6, 2016

@retr0h, ping. This issue is still waiting on your response.
click here for bot help

@ansibot
Copy link

ansibot commented Nov 22, 2016

@retr0h, ping. This issue is still waiting on your response.
click here for bot help

@ansibot
Copy link

ansibot commented Dec 6, 2016

This repository has been locked. All new issues and pullrequests should be filed in https://github.com/ansible/ansible

Please read through the repomerge page in the dev guide. The guide contains links to tools which automatically move your issue or pullrequest to the ansible/ansible repo.

@ansibot
Copy link

ansibot commented Sep 10, 2017

This issue was migrated to ansible/ansible#29244

@ansibot ansibot closed this as completed Sep 10, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants