From 9658075b826dbf1206e7d9f689b242acfeb61b3d Mon Sep 17 00:00:00 2001 From: Larry Smith Jr Date: Thu, 6 Aug 2015 21:32:09 -0400 Subject: [PATCH] changed method of determining master node --- README.md | 18 ++++++++++++------ defaults/main.yml | 2 +- tasks/rabbitmq_clustering.yml | 23 +++++++++++++++-------- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 88f3c94..28b2b03 100644 --- a/README.md +++ b/README.md @@ -10,15 +10,11 @@ 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...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 +enable_rabbitmq_clustering: false #defines if setting up a rabbitmq cluster...define here or in group_vars/group +erlang_cookie: LSKNKBELKPSTDBBCHETL #define erlang cookie for cluster...define here or in group_vars/group rabbitmq_config: - queue_name: logstash durable: true @@ -26,6 +22,16 @@ rabbitmq_config: type: fanout routing_key: logstash tags: 'ha-mode=all,ha-sync-mode=automatic' +rabbitmq_master: [] #defines the inventory host that should be considered master...define here or in group_vars/group +```` + +example... +group_vars/rabbitmq-cluster-nodes +```` +--- +enable_rabbitmq_clustering: true +config_rabbitmq_ha: false +rabbitmq_master: ans-test-1 ```` Dependencies diff --git a/defaults/main.yml b/defaults/main.yml index 95caff5..2c7ea69 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -3,7 +3,6 @@ config_rabbitmq_ha: false #defines if rabbitmq ha should be configured...define here or in group_vars/group enable_rabbitmq_clustering: false #defines if setting up a rabbitmq cluster...define here or in group_vars/group erlang_cookie: LSKNKBELKPSTDBBCHETL #define erlang cookie for cluster...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 @@ -11,3 +10,4 @@ rabbitmq_config: type: fanout routing_key: logstash tags: 'ha-mode=all,ha-sync-mode=automatic' +rabbitmq_master: [] #defines the inventory host that should be considered master...define here or in group_vars/group diff --git a/tasks/rabbitmq_clustering.yml b/tasks/rabbitmq_clustering.yml index a34ff92..a87bb2b 100644 --- a/tasks/rabbitmq_clustering.yml +++ b/tasks/rabbitmq_clustering.yml @@ -5,37 +5,44 @@ - name: rabbitmq_clustering | resetting rabbitmq app command: rabbitmqctl reset +- name: rabbitmq_clustering | stopping rabbitmq-server + service: name=rabbitmq-server state=stopped + - 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 | starting rabbitmq app +- name: rabbitmq_clustering | restarting rabbitmq-server on master + service: name=rabbitmq-server state=restarted + when: inventory_hostname == "{{ rabbitmq_master }}" + +- name: rabbitmq_clustering | starting rabbitmq app on master command: rabbitmqctl start_app register: cluster_master - when: master_rabbit_node is defined and master_rabbit_node + when: inventory_hostname == "{{ rabbitmq_master }}" - name: rabbitmq_clustering | sending sigterm to any running rabbitmq processes shell: pkill -u rabbitmq || true - when: (master_rabbit_node is defined and not master_rabbit_node) and cluster_master.changed + when: inventory_hostname != "{{ rabbitmq_master }}" and cluster_master.changed - name: rabbitmq_clustering | restarting rabbitmq-server service: name=rabbitmq-server state=restarted - when: (master_rabbit_node is defined and not master_rabbit_node) and cluster_master.changed + when: inventory_hostname != "{{ rabbitmq_master }}" and cluster_master.changed - name: rabbitmq_clustering | stopping rabbitmq app command: rabbitmqctl stop_app - when: (master_rabbit_node is defined and not master_rabbit_node) and cluster_master.changed + when: inventory_hostname != "{{ rabbitmq_master }}" and cluster_master.changed - name: rabbitmq_clustering | resetting rabbitmq app command: rabbitmqctl reset - when: (master_rabbit_node is defined and not master_rabbit_node) and cluster_master.changed + when: inventory_hostname != "{{ rabbitmq_master }}" and cluster_master.changed - name: rabbitmq_clustering | joining rabbitmq cluster command: rabbitmqctl join_cluster 'rabbit@{{ master_rabbit_node }}' - when: (master_rabbit_node is defined and not master_rabbit_node) and cluster_master.changed + when: inventory_hostname != "{{ rabbitmq_master }}" and cluster_master.changed - name: rabbitmq_clustering | starting rabbitmq app command: rabbitmqctl start_app - when: (master_rabbit_node is defined and not master_rabbit_node) and cluster_master.changed + when: inventory_hostname != "{{ rabbitmq_master }}" and cluster_master.changed - name: rabbitmq_clustering | marking as clustered file: path=/etc/rabbitmq/clustered state=touch -- 2.41.0