diff options
Diffstat (limited to 'tasks')
-rw-r--r-- | tasks/main.yml | 29 | ||||
-rw-r--r-- | tasks/rabbitmq_clustering.yml | 40 | ||||
-rw-r--r-- | tasks/rabbitmq_ha_config.yml | 30 |
3 files changed, 99 insertions, 0 deletions
diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..e74c1e5 --- /dev/null +++ b/tasks/main.yml | |||
@@ -0,0 +1,29 @@ | |||
1 | --- | ||
2 | # tasks file for ansible-rabbitmq | ||
3 | - name: Add the RabbitMQ public GPG key to the apt repo | ||
4 | apt_key: url=http://www.rabbitmq.com/rabbitmq-signing-key-public.asc state=present | ||
5 | |||
6 | - name: Add RabbitMQ to the sources list | ||
7 | apt_repository: repo='deb http://www.rabbitmq.com/debian/ testing main' update_cache=no state=present | ||
8 | |||
9 | - name: Install RabbitMQ server | ||
10 | apt: name={{ item }} update_cache=no force=yes state=installed | ||
11 | with_items: | ||
12 | - rabbitmq-server | ||
13 | |||
14 | - name: Enable the RabbitMQ Management Console | ||
15 | rabbitmq_plugin: names=rabbitmq_management state=enabled | ||
16 | notify: restart rabbitmq-server | ||
17 | |||
18 | - name: Ensure that the RabbitMQ service is running | ||
19 | service: name=rabbitmq-server state=started enabled=yes | ||
20 | |||
21 | - name: check | checking to see if already clustered | ||
22 | stat: path=/etc/rabbitmq/clustered | ||
23 | register: clustered | ||
24 | |||
25 | - include: rabbitmq_clustering.yml | ||
26 | when: enable_rabbitmq_clustering and (clustered.stat.exists != True) | ||
27 | |||
28 | - include: rabbitmq_ha_config.yml | ||
29 | when: config_rabbitmq_ha and enable_rabbitmq_clustering | ||
diff --git a/tasks/rabbitmq_clustering.yml b/tasks/rabbitmq_clustering.yml new file mode 100644 index 0000000..29db18c --- /dev/null +++ b/tasks/rabbitmq_clustering.yml | |||
@@ -0,0 +1,40 @@ | |||
1 | --- | ||
2 | - name: rabbitmq_clustering | config | stopping rabbitmq app | ||
3 | command: rabbitmqctl stop_app | ||
4 | |||
5 | - name: rabbitmq_clustering | config | resetting rabbitmq app | ||
6 | command: rabbitmqctl reset | ||
7 | |||
8 | - name: rabbitmq_clustering | config | copy erlang cookie | ||
9 | template: src=erlang.cookie.j2 dest=/var/lib/rabbitmq/.erlang.cookie owner=rabbitmq group=rabbitmq mode=0400 backup=yes | ||
10 | |||
11 | - name: rabbitmq_clustering | config | starting rabbitmq app | ||
12 | command: rabbitmqctl start_app | ||
13 | when: inventory_hostname == "{{ master_rabbit_node }}" | ||
14 | |||
15 | - name: rabbitmq_clustering | config | sending sigterm to any running rabbitmq processes | ||
16 | shell: pkill -u rabbitmq || true | ||
17 | when: inventory_hostname != "{{ master_rabbit_node }}" | ||
18 | |||
19 | - name: rabbitmq_clustering | config | restarting rabbitmq-server | ||
20 | service: name=rabbitmq-server state=restarted | ||
21 | when: inventory_hostname != "{{ master_rabbit_node }}" | ||
22 | |||
23 | - name: rabbitmq_clustering | config | stopping rabbitmq app | ||
24 | command: rabbitmqctl stop_app | ||
25 | when: inventory_hostname != "{{ master_rabbit_node }}" | ||
26 | |||
27 | - name: rabbitmq_clustering | config | resetting rabbitmq app | ||
28 | command: rabbitmqctl reset | ||
29 | when: inventory_hostname != "{{ master_rabbit_node }}" | ||
30 | |||
31 | - name: rabbitmq_clustering | config | joining rabbitmq cluster | ||
32 | command: rabbitmqctl join_cluster 'rabbit@{{ master_rabbit_node }}' | ||
33 | when: inventory_hostname != "{{ master_rabbit_node }}" | ||
34 | |||
35 | - name: rabbitmq_clustering | config | starting rabbitmq app | ||
36 | command: rabbitmqctl start_app | ||
37 | when: inventory_hostname != "{{ master_rabbit_node }}" | ||
38 | |||
39 | - name: rabbitmq_clustering | config | marking as clustered | ||
40 | file: path=/etc/rabbitmq/clustered state=touch | ||
diff --git a/tasks/rabbitmq_ha_config.yml b/tasks/rabbitmq_ha_config.yml new file mode 100644 index 0000000..5554782 --- /dev/null +++ b/tasks/rabbitmq_ha_config.yml | |||
@@ -0,0 +1,30 @@ | |||
1 | --- | ||
2 | - name: rabbitmq_ha_config | install | install rabbitMQ admin | ||
3 | shell: wget http://guest:guest@localhost:55672/cli/rabbitmqadmin | ||
4 | |||
5 | - name: Move the rabbitMQ Admin | ||
6 | shell: mv rabbitmqadmin /usr/sbin | ||
7 | |||
8 | - name: Make executable rabbitMQ Admin | ||
9 | shell: chmod +x /usr/sbin/rabbitmqadmin | ||
10 | notify: restart rabbitmq-server | ||
11 | |||
12 | - name: rabbitmq_ha_config | config | creating queue(s) | ||
13 | command: rabbitmqadmin declare queue name={{ item.queue_name }} durable={{ item.durable }} | ||
14 | run_once: true | ||
15 | with_items: rabbitmq_config | ||
16 | |||
17 | - name: rabbitmq_ha_config | config | setting up ha on queue(s) | ||
18 | rabbitmq_policy: name='ha-all' pattern='{{ item.queue_name }}' tags="{{ item.tags }}" state=present | ||
19 | run_once: true | ||
20 | with_items: rabbitmq_config | ||
21 | |||
22 | - name: rabbitmq_ha_config | config | creating exchange(s) | ||
23 | command: rabbitmqadmin declare exchange name={{ item.exchange_name }} type={{ item.type }} | ||
24 | run_once: true | ||
25 | with_items: rabbitmq_config | ||
26 | |||
27 | - name: rabbitmq_ha_config | 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 }} | ||
29 | run_once: true | ||
30 | with_items: rabbitmq_config | ||