RabbitMQ: Ansible и Hostname mismatch: node believes its host is different.

Автор: | 08/08/2018
 

Имеется Ansible плейбук, где среди прочего выполняется установка и настройка RabbitMQ.

При запуске задачи с использованием плагина rabbitmq_vhost возникает ошибка:

[simterm]

TASK [rabbitmq : Add RabbitMQ vhosts] ****
fatal: [dev.mobilebackend.domain.world]: FAILED! => {"changed": false, "cmd": "/usr/sbin/rabbitmqctl -q -n rabbit list_vhosts name tracing", "msg": "Error:********@localhost'\n- home dir: /var/lib/rabbitmq\n- cookie hash: cWvPHXMU4l0V3ALUhc3MbA==", "rc": 69, "stderr": "Error: unable to connect to node rabbit@localhost: nodedown\n\nDIAGNOSTICS\n===========\n\nattempted to contact: [rabbit@localhost]\n\nrabbit@localhost:\n  * connected to epmd (port 4369) on localhost\n  * epmd reports node 'rabbit' running on port 25672\n  * TCP connection succeeded but Erlang distribution failed\n\n  * Hostname mismatch: node \"rabbit@bm-backed-app-dev\" believes its host is different. Please ensure that hostnames resolve the same way locally and on \"rabbit@bm-backed-app-dev\"\n\n\ncurrent node details:\n- node name: 'rabbitmq-cli-54@localhost'\n- home dir: /var/lib/rabbitmq\n- cookie hash: cWvPHXMU4l0V3ALUhc3MbA==\n\n", "stderr_lines": ["Error: unable to connect to node rabbit@localhost: nodedown", "", "DIAGNOSTICS", "===========", "", "attempted to contact: [rabbit@localhost]", "", "rabbit@localhost:", "  * connected to epmd (port 4369) on localhost", "  * epmd reports node 'rabbit' running on port 25672", "  * TCP connection succeeded but Erlang distribution failed", "", "  * Hostname mismatch: node \"rabbit@bm-backed-app-dev\" believes its host is different. Please ensure that hostnames resolve the same way locally and on \"rabbit@bm-backed-app-dev\"", "", "", "current node details:", "- node name: 'rabbitmq-cli-54@localhost'", "- home dir: /var/lib/rabbitmq", "- cookie hash: cWvPHXMU4l0V3ALUhc3MbA==", ""], "stdout": "", "stdout_lines": []}

[/simterm]

Решение – добавить в вызов rabbitmq_vhost имя ноды с указанием имени хоста, в примере ниже это будет node: "rabbit@{{ set_hostname }}":

...
- name: Add RabbitMQ vhosts
  rabbitmq_vhost:
    node: "rabbit@{{ set_hostname }}"
    name: "{{ item.value.vhost }}"
    state: present
  with_dict: "{{ rabbitmq_users }}"
...

Где set_hostname – переменная, которая задаётся из hosts.ini:

...
[mobilebackend-dev:vars]
env=dev
aws_env=mobilebackend-dev
set_hostname=bm-backed-app-dev
...

Проверяем:

[simterm]

...
TASK [rabbitmq : Add RabbitMQ vhosts] ****
ok: [dev.mobilebackend.domain.world] => (item={'key': 'rabbitadmin', 'value': {'password': 'password', 'vhost': '/', 'tags': 'aministrator'}})
changed: [dev.mobilebackend.domain.world] => (item={'key': 'project1', 'value': {'password': 'password', 'vhost': '/project1', 'tags': ''}})
changed: [dev.mobilebackend.domain.world] => (item={'key': 'project2', 'value': {'password': 'password', 'vhost': '/project2', 'tags': ''}})
changed: [dev.mobilebackend.domain.world] => (item={'key': 'project3', 'value': {'password': 'password', 'vhost': '/project3', 'tags': ''}})
...

[/simterm]

Готово.