aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--README.md16
-rw-r--r--defaults/main.yml8
-rw-r--r--tasks/debian.yml16
-rw-r--r--tasks/main.yml6
-rw-r--r--tasks/rabbitmq_clustering.yml38
-rw-r--r--tasks/rabbitmq_ha_config.yml14
6 files changed, 60 insertions, 38 deletions
diff --git a/README.md b/README.md
index 14f946c..88f3c94 100644
--- a/README.md
+++ b/README.md
@@ -10,10 +10,22 @@ Any pre-requisites that may not be covered by Ansible itself or the role should
10 10
11Role Variables 11Role Variables
12-------------- 12--------------
13define in one host_vars/host config to designate the master_rabbit_node
14````
15master_rabbit_node: true
16````
13 17
14```` 18````
15enable_rabbitmq_clustering: false #defines if setting up a rabbitmq cluster 19enable_rabbitmq_clustering: false #defines if setting up a rabbitmq cluster...define here or in group_vars/group
16config_rabbitmq_ha: false #defines if rabbitmq ha should be configured 20config_rabbitmq_ha: false #defines if rabbitmq ha should be configured...define here or in group_vars/group
21master_rabbit_node: false #defines if node should be considered master...define as true in one host in host_vars/host out of all nodes to be part of cluster
22rabbitmq_config:
23 - queue_name: logstash
24 durable: true
25 exchange_name: logstash
26 type: fanout
27 routing_key: logstash
28 tags: 'ha-mode=all,ha-sync-mode=automatic'
17```` 29````
18 30
19Dependencies 31Dependencies
diff --git a/defaults/main.yml b/defaults/main.yml
index c1cd0d8..f594ced 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -2,3 +2,11 @@
2# defaults file for ansible-rabbitmq 2# defaults file for ansible-rabbitmq
3enable_rabbitmq_clustering: false #defines if setting up a rabbitmq cluster...define here or in group_vars/group 3enable_rabbitmq_clustering: false #defines if setting up a rabbitmq cluster...define here or in group_vars/group
4config_rabbitmq_ha: false #defines if rabbitmq ha should be configured...define here or in group_vars/group 4config_rabbitmq_ha: false #defines if rabbitmq ha should be configured...define here or in group_vars/group
5master_rabbit_node: false #defines if node should be considered master...define as true in one host in host_vars/host out of all nodes to be part of cluster
6rabbitmq_config:
7 - queue_name: logstash
8 durable: true
9 exchange_name: logstash
10 type: fanout
11 routing_key: logstash
12 tags: 'ha-mode=all,ha-sync-mode=automatic'
diff --git a/tasks/debian.yml b/tasks/debian.yml
index 563563a..4b38782 100644
--- a/tasks/debian.yml
+++ b/tasks/debian.yml
@@ -1,22 +1,18 @@
1--- 1---
2- name: Add the RabbitMQ public GPG key to the apt repo 2- name: debian | adding RabbitMQ public GPG key to the apt repo
3 apt_key: url=http://www.rabbitmq.com/rabbitmq-signing-key-public.asc state=present 3 apt_key: url=http://www.rabbitmq.com/rabbitmq-signing-key-public.asc state=present
4 4
5- name: Add RabbitMQ to the sources list 5- name: debian | adding RabbitMQ repo
6 apt_repository: repo='deb http://www.rabbitmq.com/debian/ testing main' update_cache=no state=present 6 apt_repository: repo='deb http://www.rabbitmq.com/debian/ testing main' update_cache=no state=present
7 7
8- name: Install RabbitMQ server 8- name: debian | installing RabbitMQ server
9 apt: name={{ item }} update_cache=no force=yes state=installed 9 apt: name={{ item }} state=present
10 with_items: 10 with_items:
11 - rabbitmq-server 11 - rabbitmq-server
12 12
13- name: Enable the RabbitMQ Management Console 13- name: debian | enabling the RabbitMQ Management Console
14 rabbitmq_plugin: names=rabbitmq_management state=enabled 14 rabbitmq_plugin: names=rabbitmq_management state=enabled
15 notify: restart rabbitmq-server 15 notify: restart rabbitmq-server
16 16
17- name: Ensure that the RabbitMQ service is running 17- name: debian | ensuring that the RabbitMQ service is running
18 service: name=rabbitmq-server state=started enabled=yes 18 service: name=rabbitmq-server state=started enabled=yes
19
20- name: check | checking to see if already clustered
21 stat: path=/etc/rabbitmq/clustered
22 register: clustered
diff --git a/tasks/main.yml b/tasks/main.yml
index 3752d78..edd55df 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -2,8 +2,12 @@
2- include: debian.yml 2- include: debian.yml
3 when: ansible_os_family == "Debian" 3 when: ansible_os_family == "Debian"
4 4
5- name: checking to see if already clustered
6 stat: path=/etc/rabbitmq/clustered
7 register: clustered
8
5- include: rabbitmq_clustering.yml 9- include: rabbitmq_clustering.yml
6 when: enable_rabbitmq_clustering and (clustered.stat.exists != True) 10 when: enable_rabbitmq_clustering and not clustered.stat.exists
7 11
8- include: rabbitmq_ha_config.yml 12- include: rabbitmq_ha_config.yml
9 when: config_rabbitmq_ha and enable_rabbitmq_clustering 13 when: config_rabbitmq_ha and enable_rabbitmq_clustering
diff --git a/tasks/rabbitmq_clustering.yml b/tasks/rabbitmq_clustering.yml
index 29db18c..a34ff92 100644
--- a/tasks/rabbitmq_clustering.yml
+++ b/tasks/rabbitmq_clustering.yml
@@ -1,40 +1,42 @@
1--- 1---
2- name: rabbitmq_clustering | config | stopping rabbitmq app 2- name: rabbitmq_clustering | stopping rabbitmq app
3 command: rabbitmqctl stop_app 3 command: rabbitmqctl stop_app
4 4
5- name: rabbitmq_clustering | config | resetting rabbitmq app 5- name: rabbitmq_clustering | resetting rabbitmq app
6 command: rabbitmqctl reset 6 command: rabbitmqctl reset
7 7
8- name: rabbitmq_clustering | config | copy erlang cookie 8- name: rabbitmq_clustering | copy erlang cookie
9 template: src=erlang.cookie.j2 dest=/var/lib/rabbitmq/.erlang.cookie owner=rabbitmq group=rabbitmq mode=0400 backup=yes 9 template: src=erlang.cookie.j2 dest=/var/lib/rabbitmq/.erlang.cookie owner=rabbitmq group=rabbitmq mode=0400 backup=yes
10 10
11- name: rabbitmq_clustering | config | starting rabbitmq app 11- name: rabbitmq_clustering | starting rabbitmq app
12 command: rabbitmqctl start_app 12 command: rabbitmqctl start_app
13 when: inventory_hostname == "{{ master_rabbit_node }}" 13 register: cluster_master
14 when: master_rabbit_node is defined and master_rabbit_node
14 15
15- name: rabbitmq_clustering | config | sending sigterm to any running rabbitmq processes 16- name: rabbitmq_clustering | sending sigterm to any running rabbitmq processes
16 shell: pkill -u rabbitmq || true 17 shell: pkill -u rabbitmq || true
17 when: inventory_hostname != "{{ master_rabbit_node }}" 18 when: (master_rabbit_node is defined and not master_rabbit_node) and cluster_master.changed
18 19
19- name: rabbitmq_clustering | config | restarting rabbitmq-server 20- name: rabbitmq_clustering | restarting rabbitmq-server
20 service: name=rabbitmq-server state=restarted 21 service: name=rabbitmq-server state=restarted
21 when: inventory_hostname != "{{ master_rabbit_node }}" 22 when: (master_rabbit_node is defined and not master_rabbit_node) and cluster_master.changed
22 23
23- name: rabbitmq_clustering | config | stopping rabbitmq app 24- name: rabbitmq_clustering | stopping rabbitmq app
24 command: rabbitmqctl stop_app 25 command: rabbitmqctl stop_app
25 when: inventory_hostname != "{{ master_rabbit_node }}" 26 when: (master_rabbit_node is defined and not master_rabbit_node) and cluster_master.changed
26 27
27- name: rabbitmq_clustering | config | resetting rabbitmq app 28- name: rabbitmq_clustering | resetting rabbitmq app
28 command: rabbitmqctl reset 29 command: rabbitmqctl reset
29 when: inventory_hostname != "{{ master_rabbit_node }}" 30 when: (master_rabbit_node is defined and not master_rabbit_node) and cluster_master.changed
30 31
31- name: rabbitmq_clustering | config | joining rabbitmq cluster 32- name: rabbitmq_clustering | joining rabbitmq cluster
32 command: rabbitmqctl join_cluster 'rabbit@{{ master_rabbit_node }}' 33 command: rabbitmqctl join_cluster 'rabbit@{{ master_rabbit_node }}'
33 when: inventory_hostname != "{{ master_rabbit_node }}" 34 when: (master_rabbit_node is defined and not master_rabbit_node) and cluster_master.changed
34 35
35- name: rabbitmq_clustering | config | starting rabbitmq app 36- name: rabbitmq_clustering | starting rabbitmq app
36 command: rabbitmqctl start_app 37 command: rabbitmqctl start_app
37 when: inventory_hostname != "{{ master_rabbit_node }}" 38 when: (master_rabbit_node is defined and not master_rabbit_node) and cluster_master.changed
38 39
39- name: rabbitmq_clustering | config | marking as clustered 40- name: rabbitmq_clustering | marking as clustered
40 file: path=/etc/rabbitmq/clustered state=touch 41 file: path=/etc/rabbitmq/clustered state=touch
42 when: cluster_master.changed
diff --git a/tasks/rabbitmq_ha_config.yml b/tasks/rabbitmq_ha_config.yml
index 5554782..3a82c59 100644
--- a/tasks/rabbitmq_ha_config.yml
+++ b/tasks/rabbitmq_ha_config.yml
@@ -1,30 +1,30 @@
1--- 1---
2- name: rabbitmq_ha_config | install | install rabbitMQ admin 2- name: rabbitmq_ha_config | install rabbitMQ admin
3 shell: wget http://guest:guest@localhost:55672/cli/rabbitmqadmin 3 shell: wget http://guest:guest@localhost:55672/cli/rabbitmqadmin
4 4
5- name: Move the rabbitMQ Admin 5- name: rabbitmq_ha_config | moving the rabbitMQ Admin
6 shell: mv rabbitmqadmin /usr/sbin 6 shell: mv rabbitmqadmin /usr/sbin
7 7
8- name: Make executable rabbitMQ Admin 8- name: rabbitmq_ha_config | making executable rabbitMQ Admin
9 shell: chmod +x /usr/sbin/rabbitmqadmin 9 shell: chmod +x /usr/sbin/rabbitmqadmin
10 notify: restart rabbitmq-server 10 notify: restart rabbitmq-server
11 11
12- name: rabbitmq_ha_config | config | creating queue(s) 12- name: rabbitmq_ha_config | creating queue(s)
13 command: rabbitmqadmin declare queue name={{ item.queue_name }} durable={{ item.durable }} 13 command: rabbitmqadmin declare queue name={{ item.queue_name }} durable={{ item.durable }}
14 run_once: true 14 run_once: true
15 with_items: rabbitmq_config 15 with_items: rabbitmq_config
16 16
17- name: rabbitmq_ha_config | config | setting up ha on queue(s) 17- name: rabbitmq_ha_config | setting up ha on queue(s)
18 rabbitmq_policy: name='ha-all' pattern='{{ item.queue_name }}' tags="{{ item.tags }}" state=present 18 rabbitmq_policy: name='ha-all' pattern='{{ item.queue_name }}' tags="{{ item.tags }}" state=present
19 run_once: true 19 run_once: true
20 with_items: rabbitmq_config 20 with_items: rabbitmq_config
21 21
22- name: rabbitmq_ha_config | config | creating exchange(s) 22- name: rabbitmq_ha_config | creating exchange(s)
23 command: rabbitmqadmin declare exchange name={{ item.exchange_name }} type={{ item.type }} 23 command: rabbitmqadmin declare exchange name={{ item.exchange_name }} type={{ item.type }}
24 run_once: true 24 run_once: true
25 with_items: rabbitmq_config 25 with_items: rabbitmq_config
26 26
27- name: rabbitmq_ha_config | config | creating binding(s) 27- name: rabbitmq_ha_config | creating binding(s)
28 command: rabbitmqadmin declare binding source={{ item.exchange_name }} destination_type="queue" destination={{ item.queue_name }} routing_key={{ item.routing_key }} 28 command: rabbitmqadmin declare binding source={{ item.exchange_name }} destination_type="queue" destination={{ item.queue_name }} routing_key={{ item.routing_key }}
29 run_once: true 29 run_once: true
30 with_items: rabbitmq_config 30 with_items: rabbitmq_config