-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.yaml
73 lines (61 loc) · 2.29 KB
/
plugin.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
---
- name: Enable RabbitMQ Web Dashboard and Create Admin User with OpenSSL Password
hosts: localhost
become: true
connection: local
vars:
rabbitmq_user: "admin"
rabbitmq_vhost: "/"
password_file: "/tmp/rabbitmq_admin_credentials.txt"
tasks:
- name: Install OpenSSL and RabbitMQ Management Plugin
apt:
name:
- openssl
- rabbitmq-server
state: present
update_cache: true
- name: Ensure RabbitMQ service is running
systemd:
name: rabbitmq-server
state: started
enabled: true
- name: Enable RabbitMQ Management Plugin
command: rabbitmq-plugins enable rabbitmq_management
register: plugin_enable
changed_when: "'enabled' in plugin_enable.stdout or 'already enabled' in plugin_enable.stdout"
- name: Generate secure password using OpenSSL
shell: openssl rand -base64 16
register: generated_password
changed_when: false
- name: Save RabbitMQ admin credentials to a file
copy:
dest: "{{ password_file }}"
mode: '0600'
content: |
RabbitMQ Admin Credentials
==========================
Username: {{ rabbitmq_user }}
Password: {{ generated_password.stdout }}
- name: Check if RabbitMQ admin user already exists
command: rabbitmqctl list_users
register: existing_users
changed_when: false
- name: Create RabbitMQ admin user if not exists
command: rabbitmqctl add_user {{ rabbitmq_user }} {{ generated_password.stdout }}
when: existing_users.stdout_lines | select('search', '^' ~ rabbitmq_user ~ '\\b') | list | length == 0
- name: Set permissions for admin user
command: rabbitmqctl set_permissions -p {{ rabbitmq_vhost }} {{ rabbitmq_user }} ".*" ".*" ".*"
- name: Set administrator tag to admin user
command: rabbitmqctl set_user_tags {{ rabbitmq_user }} administrator
- name: Restart RabbitMQ service to apply changes
systemd:
name: rabbitmq-server
state: restarted
- name: Show final output
debug:
msg: |
✅ RabbitMQ setup complete.
🖥 Web Dashboard URL: http://<your-server-ip>:15672
👤 Username: {{ rabbitmq_user }}
🔐 Password saved in: {{ password_file }}