Skip to content

Commit

Permalink
fix playbook to create multinode rabbitmq cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
amitsagtani97 committed Sep 6, 2023
1 parent 1b105c4 commit cc5c493
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 30 deletions.
3 changes: 2 additions & 1 deletion ansible/roles/rabbitmq-cluster/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ keyfile_dest: "/etc/rabbitmq/key.pem"
# Queues can optionally be made mirrored across all nodes, or exactly N number of nodes
# By enabling this variable to true, there will be 1 queue master and 1 queue mirror.
# If the node running the queue master becomes unavailable, the queue mirror will be automatically promoted to master.
backup_queues_in_two_nodes: true
backup_queues_in_two_nodes: true
rabbitmq_add_host_resolution_entries: false
24 changes: 0 additions & 24 deletions ansible/roles/rabbitmq-cluster/tasks/config.yaml

This file was deleted.

34 changes: 34 additions & 0 deletions ansible/roles/rabbitmq-cluster/tasks/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
- name: rabbitmq default file
template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: root
group: root
mode: 0644
with_items:
- { src: etc/default/rabbitmq-server.j2 , dest: /etc/default/rabbitmq-server }
- { src: etc/rabbitmq/rabbitmq.config.j2, dest: /etc/rabbitmq/rabbitmq.config }
# - { src: etc/rabbitmq/rabbitmq-env.conf.j2, dest: /etc/rabbitmq/rabbitmq-env.conf }
notify:
restart rabbitmq-server

- name: restart rabbitmq-server
service:
name: rabbitmq-server
state: restarted

# - name: Enable the plugins is installed
# rabbitmq_plugin:
# names: "{{ item }}"
# prefix: /usr/lib/rabbitmq
# state: enabled
# new_only: yes
# with_items: "{{ rabbitmq_plugins }}"
# notify:
# restart rabbitmq-server

- name: restart rabbitmq-server
service:
name: rabbitmq-server
state: restarted
14 changes: 14 additions & 0 deletions ansible/roles/rabbitmq-cluster/tasks/configure_dns.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
- name: Update /etc/hosts on rmq-cluster nodes
hosts: rmq-cluster
become: yes # This allows the playbook to run with elevated privileges

tasks:
- name: Add entries to /etc/hosts
lineinfile:
path: /etc/hosts
regexp: "^{{ hostvars[item].ansible_default_ipv4.address }}\\s+{{ item }}\\s+rabbit@{{ item }}$"
line: "{{ hostvars[item].ansible_default_ipv4.address }} {{ item }} rabbit@{{ item }}"
insertbefore: EOF
with_items: "{{ groups['rmq-cluster'] }}"
when: item != inventory_hostname
2 changes: 1 addition & 1 deletion ansible/roles/rabbitmq-cluster/tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
pkg: "{{ item }}"
state: present
with_items:
- rabbitmq-server
- rabbitmq-server
9 changes: 9 additions & 0 deletions ansible/roles/rabbitmq-cluster/tasks/join_cluster.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- name: stop rabbitmq app
command: rabbitmqctl stop_app

- name: add this node to cluster
command: rabbitmqctl join_cluster rabbit@{{ rabbitmq_cluster_master }}

- name: start rabbitmq app
command: rabbitmqctl start_app
7 changes: 5 additions & 2 deletions ansible/roles/rabbitmq-cluster/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

- include_tasks: install.yml

- include_tasks: configure_dns.yml
when: rabbitmq_add_host_resolution_entries == true

- include_tasks: erlang_cookie.yml
when: rabbitmq_create_cluster

Expand All @@ -12,12 +15,12 @@

- include_tasks: config.yml

- include_tasks: service.yml
#- include_tasks: service.yml

- include_tasks: cluster.yml
when: rabbitmq_create_cluster == true

- include_tasks: create_users.yml

- include_tasks: enable_ha_queues.yml
when: backup_queues_in_two_nodes
when: backup_queues_in_two_nodes
2 changes: 1 addition & 1 deletion ansible/setup-offline-sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
daemon-reload: yes

- name: Set up offline repositories and remove online ones
hosts: k8s-cluster:etcd:restund:cassandra:elasticsearch:minio
hosts: k8s-cluster:etcd:restund:cassandra:elasticsearch:minio:rmq-cluster
tasks:
- name: Bail if GPG is not installed or installable.
apt:
Expand Down
8 changes: 7 additions & 1 deletion offline/docs_ubuntu_22.04.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,13 @@ In order to automatically generate deeplinks, Edit the minio variables in `[mini

### Configuring rabbitmq

Add the nodes in which you want to run rabbitmq to the `[rmq-cluster]` group. Also, update the ansible/roles/rabbimq-cluster/defaults/main.yml file with the correct configurations for your environment.
Add the nodes in which you want to run rabbitmq to the `[rmq-cluster]` group. Also, update the `ansible/roles/rabbimq-cluster/defaults/main.yml` file with the correct configurations for your environment.

Important: RabbitMQ nodes address each other using a node name, for e.g rabbitmq@ansnode1
Please refer to official doc and configure your DNS based on the setup - https://www.rabbitmq.com/clustering.html#cluster-formation-requirements

For adding entries to local host file(/etc/hosts), set `rabbitmq_add_host_resolution_entries` to true in `ansible/roles/rabbimq-cluster/defaults/main.yml`



### Example hosts.ini
Expand Down

0 comments on commit cc5c493

Please sign in to comment.