Skip to content

Instantly share code, notes, and snippets.

@shichi-at-nttr
Last active December 22, 2017 06:57
Show Gist options
  • Save shichi-at-nttr/52085f3b269cdb0c1dc9c80b1b45e6cc to your computer and use it in GitHub Desktop.
Save shichi-at-nttr/52085f3b269cdb0c1dc9c80b1b45e6cc to your computer and use it in GitHub Desktop.
Ansible2.4でRabbitMQ3.7を構成する際のrabbitmq_policyエラー回避方法

目的

Ansible 2.4 から RabbitMQ 3.7 のポリシーを構成をするにあたり、 RabbitMQ 3.6 までは発生しなかったエラーを回避するために macOS上のansibleにパッチを当てる。

修正箇所

  • パス: /usr/local/Cellar/ansible/2.4.2.0_1/libexec/lib/python2.7/site-packages/ansible/modules/messaging
  • ファイル: rabbitmq_policy.py

修正内容:

116,118c116,119
<             policy_name = policy.split('\t')[1]
<             if policy_name == self._name:
<                 return True
---
>             if policy != '':
>                 policy_name = policy.split('\t')[1]
>                 if policy_name == self._name:
>                     return True

対象とする事象

Ansible 2.4.2 から RabbitMQ 3.7.0 を構成する際、rabbitmq_policy の箇所で以下のエラーが発生する

fatal: [node1]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 
127.0.0.1 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  
File \"/tmp/ansible_sqost_hl/ansible_module_rabbitmq_policy.py\", line 172, in <module>\r\n    
main()\r\n  File \"/tmp/ansible_sqost_hl/ansible_module_rabbitmq_policy.py\", line 159, in 
main\r\n    if rabbitmq_policy.list():\r\n  File \"/tmp/ansible_sqost_hl/ansible_module_
rabbitmq_policy.py\", line 116, in list\r\n    policy_name = policy.split('\\t')[1]\r\nIndexError: 
list index out of range\r\n", "msg": "MODULE FAILURE", "rc": 0}

原因となる挙動の詳細

rabbitmqctl list_policies した際の出力を比較する

vhostにポリシーが設定されていない場合

RabbitMQ 3.6.14

なにも出力されない

$ sudo rabbitmqctl list_policies -q | od -c
0000000

RabbitMQ 3.7.0

空行が1行出力される

$ sudo rabbitmqctl -q list_policies | od -c
0000000 \n
0000001

vhostにポリシーが設定されている場合

RabbitMQ 3.7.0

余分な空行は出力されない

$ sudo rabbitmqctl -q list_policies | od -c
0000000   /  \t   H   A  \t   .   *  \t   a   l   l  \t   {   "   h   a
0000020   -   m   o   d   e   "   :   "   a   l   l   "   }  \t   0  \n
0000040

python上のエラー

空行に対して policy.split('¥t') は可能だが、そこから [1] を取り出すことができないのでエラーとなる。

このため、空行であれば policy_name = policy.split('\t')[1] (以降)をスキップすることでエラーを回避する。 (これが冒頭のパッチ)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment