Write an ansible playbook to install rabbitmq-server and enable default plugins

Divesh
2 min readFeb 12, 2023

--

rabbitmq

Rabbitmq broker federation link creation you need to install the rabbitmq ignore if already installed. Just enable the plugins via rabbitmqctl man page.

---
- name: Install RabbitMQ and Enable Federation Management Plugins
hosts: your-server #put the target server ip or just mention localhost for testing
become: yes

tasks:
- name: Add RabbitMQ GPG Key
apt_key:
url: "https://www.rabbitmq.com/rabbitmq-release-signing-key.asc"
state: present

- name: Add RabbitMQ APT Repository
apt_repository:
repo: deb https://dl.bintray.com/rabbitmq/debian {{ ansible_distribution_release }} main
state: present

- name: Install RabbitMQ Server
apt:
name: rabbitmq-server
state: present

- name: Enable RabbitMQ Plugins
rabbitmq_plugin:
name: "{{ item }}"
state: enabled
with_items:
- rabbitmq_federation
- rabbitmq_federation_management
- rabbitmq_management #you can list as many plusgins you require here.

- name: Restart RabbitMQ Service
systemd:
name: rabbitmq-server
state: restarted

In this playbook, we first add the RabbitMQ GPG key and APT repository to the target server(s) using the apt_key and apt_repository modules respectively. We then use the apt module to install the RabbitMQ server package.

Next, we enable the RabbitMQ federation and federation management plugins using the rabbitmq_plugin module. We use a loop with the with_items keyword to enable both plugins. Finally, we restart the RabbitMQ service using the systemd module.

Note that this is just a sample playbook, and you may need to modify it to suit your specific requirements. Additionally, you will need to create an inventory file that specifies the IP address or hostname of your target server, and ensure that Ansible is installed on your local machine.

--

--

Divesh
Divesh

Written by Divesh

An Architect, A DevOps Engineer, An Automation master, A Kubernetes Security Specialist and always willing to help because helping others is my favourite task.

No responses yet