From eb299d9b8716d8c5b0bdede17e29ada1f623fe43 Mon Sep 17 00:00:00 2001 From: Larry Smith Jr Date: Wed, 29 Jul 2015 18:38:22 -0400 Subject: first commit --- tasks/main.yml | 29 +++++++++++++++++++++++++++++ tasks/rabbitmq_clustering.yml | 40 ++++++++++++++++++++++++++++++++++++++++ tasks/rabbitmq_ha_config.yml | 30 ++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 tasks/main.yml create mode 100644 tasks/rabbitmq_clustering.yml create mode 100644 tasks/rabbitmq_ha_config.yml (limited to 'tasks') 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 @@ +--- +# tasks file for ansible-rabbitmq +- name: Add the RabbitMQ public GPG key to the apt repo + apt_key: url=http://www.rabbitmq.com/rabbitmq-signing-key-public.asc state=present + +- name: Add RabbitMQ to the sources list + apt_repository: repo='deb http://www.rabbitmq.com/debian/ testing main' update_cache=no state=present + +- name: Install RabbitMQ server + apt: name={{ item }} update_cache=no force=yes state=installed + with_items: + - rabbitmq-server + +- name: Enable the RabbitMQ Management Console + rabbitmq_plugin: names=rabbitmq_management state=enabled + notify: restart rabbitmq-server + +- name: Ensure that the RabbitMQ service is running + service: name=rabbitmq-server state=started enabled=yes + +- name: check | checking to see if already clustered + stat: path=/etc/rabbitmq/clustered + register: clustered + +- include: rabbitmq_clustering.yml + when: enable_rabbitmq_clustering and (clustered.stat.exists != True) + +- include: rabbitmq_ha_config.yml + 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 @@ +--- +- name: rabbitmq_clustering | config | stopping rabbitmq app + command: rabbitmqctl stop_app + +- name: rabbitmq_clustering | config | resetting rabbitmq app + command: rabbitmqctl reset + +- name: rabbitmq_clustering | config | copy erlang cookie + template: src=erlang.cookie.j2 dest=/var/lib/rabbitmq/.erlang.cookie owner=rabbitmq group=rabbitmq mode=0400 backup=yes + +- name: rabbitmq_clustering | config | starting rabbitmq app + command: rabbitmqctl start_app + when: inventory_hostname == "{{ master_rabbit_node }}" + +- name: rabbitmq_clustering | config | sending sigterm to any running rabbitmq processes + shell: pkill -u rabbitmq || true + when: inventory_hostname != "{{ master_rabbit_node }}" + +- name: rabbitmq_clustering | config | restarting rabbitmq-server + service: name=rabbitmq-server state=restarted + when: inventory_hostname != "{{ master_rabbit_node }}" + +- name: rabbitmq_clustering | config | stopping rabbitmq app + command: rabbitmqctl stop_app + when: inventory_hostname != "{{ master_rabbit_node }}" + +- name: rabbitmq_clustering | config | resetting rabbitmq app + command: rabbitmqctl reset + when: inventory_hostname != "{{ master_rabbit_node }}" + +- name: rabbitmq_clustering | config | joining rabbitmq cluster + command: rabbitmqctl join_cluster 'rabbit@{{ master_rabbit_node }}' + when: inventory_hostname != "{{ master_rabbit_node }}" + +- name: rabbitmq_clustering | config | starting rabbitmq app + command: rabbitmqctl start_app + when: inventory_hostname != "{{ master_rabbit_node }}" + +- name: rabbitmq_clustering | config | marking as clustered + 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 @@ +--- +- name: rabbitmq_ha_config | install | install rabbitMQ admin + shell: wget http://guest:guest@localhost:55672/cli/rabbitmqadmin + +- name: Move the rabbitMQ Admin + shell: mv rabbitmqadmin /usr/sbin + +- name: Make executable rabbitMQ Admin + shell: chmod +x /usr/sbin/rabbitmqadmin + notify: restart rabbitmq-server + +- name: rabbitmq_ha_config | config | creating queue(s) + command: rabbitmqadmin declare queue name={{ item.queue_name }} durable={{ item.durable }} + run_once: true + with_items: rabbitmq_config + +- name: rabbitmq_ha_config | config | setting up ha on queue(s) + rabbitmq_policy: name='ha-all' pattern='{{ item.queue_name }}' tags="{{ item.tags }}" state=present + run_once: true + with_items: rabbitmq_config + +- name: rabbitmq_ha_config | config | creating exchange(s) + command: rabbitmqadmin declare exchange name={{ item.exchange_name }} type={{ item.type }} + run_once: true + with_items: rabbitmq_config + +- name: rabbitmq_ha_config | config | creating binding(s) + command: rabbitmqadmin declare binding source={{ item.exchange_name }} destination_type="queue" destination={{ item.queue_name }} routing_key={{ item.routing_key }} + run_once: true + with_items: rabbitmq_config -- cgit v1.2.3