From a290f6cfbff072c146c0873160672baf9059390a Mon Sep 17 00:00:00 2001 From: Larry Smith Jr Date: Thu, 6 Aug 2015 20:57:38 -0400 Subject: updated all tasks, cleaned up formatting --- README.md | 16 ++++++++++++++-- defaults/main.yml | 8 ++++++++ tasks/debian.yml | 16 ++++++---------- tasks/main.yml | 6 +++++- tasks/rabbitmq_clustering.yml | 38 ++++++++++++++++++++------------------ tasks/rabbitmq_ha_config.yml | 14 +++++++------- 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 Role Variables -------------- +define in one host_vars/host config to designate the master_rabbit_node +```` +master_rabbit_node: true +```` ```` -enable_rabbitmq_clustering: false #defines if setting up a rabbitmq cluster -config_rabbitmq_ha: false #defines if rabbitmq ha should be configured +enable_rabbitmq_clustering: false #defines if setting up a rabbitmq cluster...define here or in group_vars/group +config_rabbitmq_ha: false #defines if rabbitmq ha should be configured...define here or in group_vars/group +master_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 +rabbitmq_config: + - queue_name: logstash + durable: true + exchange_name: logstash + type: fanout + routing_key: logstash + tags: 'ha-mode=all,ha-sync-mode=automatic' ```` Dependencies 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 @@ # defaults file for ansible-rabbitmq enable_rabbitmq_clustering: false #defines if setting up a rabbitmq cluster...define here or in group_vars/group config_rabbitmq_ha: false #defines if rabbitmq ha should be configured...define here or in group_vars/group +master_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 +rabbitmq_config: + - queue_name: logstash + durable: true + exchange_name: logstash + type: fanout + routing_key: logstash + 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 @@ --- -- name: Add the RabbitMQ public GPG key to the apt repo +- name: debian | adding 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 +- name: debian | adding RabbitMQ repo 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 +- name: debian | installing RabbitMQ server + apt: name={{ item }} state=present with_items: - rabbitmq-server -- name: Enable the RabbitMQ Management Console +- name: debian | enabling the RabbitMQ Management Console rabbitmq_plugin: names=rabbitmq_management state=enabled notify: restart rabbitmq-server -- name: Ensure that the RabbitMQ service is running +- name: debian | ensuring 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 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 @@ - include: debian.yml when: ansible_os_family == "Debian" +- name: 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) + when: enable_rabbitmq_clustering and not clustered.stat.exists - 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 index 29db18c..a34ff92 100644 --- a/tasks/rabbitmq_clustering.yml +++ b/tasks/rabbitmq_clustering.yml @@ -1,40 +1,42 @@ --- -- name: rabbitmq_clustering | config | stopping rabbitmq app +- name: rabbitmq_clustering | stopping rabbitmq app command: rabbitmqctl stop_app -- name: rabbitmq_clustering | config | resetting rabbitmq app +- name: rabbitmq_clustering | resetting rabbitmq app command: rabbitmqctl reset -- name: rabbitmq_clustering | config | copy erlang cookie +- name: rabbitmq_clustering | 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 +- name: rabbitmq_clustering | starting rabbitmq app command: rabbitmqctl start_app - when: inventory_hostname == "{{ master_rabbit_node }}" + register: cluster_master + when: master_rabbit_node is defined and master_rabbit_node -- name: rabbitmq_clustering | config | sending sigterm to any running rabbitmq processes +- name: rabbitmq_clustering | sending sigterm to any running rabbitmq processes shell: pkill -u rabbitmq || true - when: inventory_hostname != "{{ master_rabbit_node }}" + when: (master_rabbit_node is defined and not master_rabbit_node) and cluster_master.changed -- name: rabbitmq_clustering | config | restarting rabbitmq-server +- name: rabbitmq_clustering | restarting rabbitmq-server service: name=rabbitmq-server state=restarted - when: inventory_hostname != "{{ master_rabbit_node }}" + when: (master_rabbit_node is defined and not master_rabbit_node) and cluster_master.changed -- name: rabbitmq_clustering | config | stopping rabbitmq app +- name: rabbitmq_clustering | stopping rabbitmq app command: rabbitmqctl stop_app - when: inventory_hostname != "{{ master_rabbit_node }}" + when: (master_rabbit_node is defined and not master_rabbit_node) and cluster_master.changed -- name: rabbitmq_clustering | config | resetting rabbitmq app +- name: rabbitmq_clustering | resetting rabbitmq app command: rabbitmqctl reset - when: inventory_hostname != "{{ master_rabbit_node }}" + when: (master_rabbit_node is defined and not master_rabbit_node) and cluster_master.changed -- name: rabbitmq_clustering | config | joining rabbitmq cluster +- name: rabbitmq_clustering | joining rabbitmq cluster command: rabbitmqctl join_cluster 'rabbit@{{ master_rabbit_node }}' - when: inventory_hostname != "{{ master_rabbit_node }}" + when: (master_rabbit_node is defined and not master_rabbit_node) and cluster_master.changed -- name: rabbitmq_clustering | config | starting rabbitmq app +- name: rabbitmq_clustering | starting rabbitmq app command: rabbitmqctl start_app - when: inventory_hostname != "{{ master_rabbit_node }}" + when: (master_rabbit_node is defined and not master_rabbit_node) and cluster_master.changed -- name: rabbitmq_clustering | config | marking as clustered +- name: rabbitmq_clustering | marking as clustered file: path=/etc/rabbitmq/clustered state=touch + 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 @@ --- -- name: rabbitmq_ha_config | install | install rabbitMQ admin +- name: rabbitmq_ha_config | install rabbitMQ admin shell: wget http://guest:guest@localhost:55672/cli/rabbitmqadmin -- name: Move the rabbitMQ Admin +- name: rabbitmq_ha_config | moving the rabbitMQ Admin shell: mv rabbitmqadmin /usr/sbin -- name: Make executable rabbitMQ Admin +- name: rabbitmq_ha_config | making executable rabbitMQ Admin shell: chmod +x /usr/sbin/rabbitmqadmin notify: restart rabbitmq-server -- name: rabbitmq_ha_config | config | creating queue(s) +- name: rabbitmq_ha_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) +- name: rabbitmq_ha_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) +- name: rabbitmq_ha_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) +- name: rabbitmq_ha_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