From 93a297c59940c7cfe88afe0f9110af5b4be521e3 Mon Sep 17 00:00:00 2001 From: Larry Smith Jr Date: Fri, 13 Nov 2015 02:56:48 -0500 Subject: updated tasks, fixed broken HA configuration tasks --- tasks/debian.yml | 21 ++++++++++++++++----- tasks/main.yml | 2 ++ tasks/rabbitmq_clustering.yml | 24 +++++++++++++++++++----- tasks/rabbitmq_ha_config.yml | 18 ++++++++++++++++-- tasks/rabbitmq_users.yml | 27 +++++++++++++++++++++++++++ 5 files changed, 80 insertions(+), 12 deletions(-) create mode 100644 tasks/rabbitmq_users.yml (limited to 'tasks') diff --git a/tasks/debian.yml b/tasks/debian.yml index 4b38782..12ddd3b 100644 --- a/tasks/debian.yml +++ b/tasks/debian.yml @@ -1,18 +1,29 @@ --- - 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 + apt_key: + url: "{{ rabbitmq_debian_repo_key }}" + state: present - name: debian | adding RabbitMQ repo - apt_repository: repo='deb http://www.rabbitmq.com/debian/ testing main' update_cache=no state=present + apt_repository: + repo: "{{ rabbitmq_debian_repo }}" + state: present - name: debian | installing RabbitMQ server - apt: name={{ item }} state=present + apt: + name: "{{ item }}" + state: present with_items: - rabbitmq-server - name: debian | enabling the RabbitMQ Management Console - rabbitmq_plugin: names=rabbitmq_management state=enabled + rabbitmq_plugin: + names: rabbitmq_management + state: enabled notify: restart rabbitmq-server - name: debian | ensuring that the RabbitMQ service is running - service: name=rabbitmq-server state=started enabled=yes + service: + name: rabbitmq-server + state: started + enabled: yes diff --git a/tasks/main.yml b/tasks/main.yml index cd24ad2..bde00da 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -11,3 +11,5 @@ - include: rabbitmq_ha_config.yml when: config_rabbitmq_ha and enable_rabbitmq_clustering + +- include: rabbitmq_users.yml diff --git a/tasks/rabbitmq_clustering.yml b/tasks/rabbitmq_clustering.yml index 348662a..f9b5157 100644 --- a/tasks/rabbitmq_clustering.yml +++ b/tasks/rabbitmq_clustering.yml @@ -6,7 +6,9 @@ command: rabbitmqctl reset - name: rabbitmq_clustering | stopping rabbitmq-server - service: name=rabbitmq-server state=stopped + service: + name: rabbitmq-server + state: stopped #- name: grabbing erlang cookie # shell: cat /var/lib/rabbitmq/.erlang.cookie @@ -14,11 +16,19 @@ # when: inventory_hostname == "{{ rabbitmq_master }}" - name: rabbitmq_clustering | copy erlang cookie - template: src=erlang.cookie.j2 dest={{ erlang_cookie_file }} owner=rabbitmq group=rabbitmq mode=0400 backup=yes + template: + src: erlang.cookie.j2 + dest: "{{ erlang_cookie_file }}" + owner: rabbitmq + group: rabbitmq + mode: 0400 + backup: yes #backing up in case the need to recover # when: inventory_hostname != "{{ rabbitmq_master }}" - name: rabbitmq_clustering | restarting rabbitmq-server on master - service: name=rabbitmq-server state=restarted + service: + name: rabbitmq-server + state: restarted when: inventory_hostname == "{{ rabbitmq_master }}" - name: rabbitmq_clustering | starting rabbitmq app on master @@ -31,7 +41,9 @@ when: inventory_hostname != "{{ rabbitmq_master }}" - name: rabbitmq_clustering | restarting rabbitmq-server - service: name=rabbitmq-server state=restarted + service: + name: rabbitmq-server + state: restarted when: inventory_hostname != "{{ rabbitmq_master }}" - name: rabbitmq_clustering | stopping rabbitmq app @@ -52,5 +64,7 @@ when: inventory_hostname != "{{ rabbitmq_master }}" - name: rabbitmq_clustering | marking as clustered - file: path=/etc/rabbitmq/clustered state=touch + file: + path: /etc/rabbitmq/clustered + state: touch when: cluster_master.changed or cluster_joined.changed diff --git a/tasks/rabbitmq_ha_config.yml b/tasks/rabbitmq_ha_config.yml index c048aed..3cbc382 100644 --- a/tasks/rabbitmq_ha_config.yml +++ b/tasks/rabbitmq_ha_config.yml @@ -1,13 +1,21 @@ --- +- name: rabbitmq_ha_config | checking if rabbitmqadmin is installed + stat: + path: /usr/sbin/rabbitmqadmin + register: rabbitmqadmin_check + - name: rabbitmq_ha_config | install rabbitMQ admin - shell: wget http://guest:guest@localhost:55672/cli/rabbitmqadmin + shell: wget http://guest:guest@localhost:15672/cli/rabbitmqadmin + when: not rabbitmqadmin_check.stat.exists - name: rabbitmq_ha_config | moving the rabbitMQ Admin shell: mv rabbitmqadmin /usr/sbin + when: not rabbitmqadmin_check.stat.exists - name: rabbitmq_ha_config | making executable rabbitMQ Admin shell: chmod +x /usr/sbin/rabbitmqadmin notify: restart rabbitmq-server + when: not rabbitmqadmin_check.stat.exists - name: rabbitmq_ha_config | creating queue(s) command: rabbitmqadmin declare queue name={{ item.queue_name }} durable={{ item.durable|lower }} @@ -15,7 +23,11 @@ with_items: rabbitmq_config - name: rabbitmq_ha_config | setting up ha on queue(s) - rabbitmq_policy: name='ha-all' pattern='{{ item.queue_name }}' tags="{{ item.tags }}" state=present + rabbitmq_policy: + name: "ha-all" + pattern: "{{ item.queue_name }}" + tags: "{{ item.tags }}" + state: present run_once: true with_items: rabbitmq_config @@ -23,8 +35,10 @@ command: rabbitmqadmin declare exchange name={{ item.exchange_name }} type={{ item.type }} run_once: true with_items: rabbitmq_config + when: item.exchange_name is defined - 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 + when: item.exchange_name is defined diff --git a/tasks/rabbitmq_users.yml b/tasks/rabbitmq_users.yml new file mode 100644 index 0000000..e14d390 --- /dev/null +++ b/tasks/rabbitmq_users.yml @@ -0,0 +1,27 @@ +--- +- name: rabbitmq_users | creating rabbitmq users + rabbitmq_user: + name: "{{ item.name }}" + password: "{{ item.password }}" + vhost: "{{ item.vhost }}" + configure_priv: "{{ item.configure_priv }}" + read_priv: "{{ item.read_priv }}" + write_priv: "{{ item.write_priv }}" + tags: "{{ item.tags }}" + state: present + with_items: rabbitmq_users + when: (enable_rabbitmq_clustering is defined and not enable_rabbitmq_clustering) or enable_rabbitmq_clustering is not defined + +- name: rabbitmq_users | creating rabbitmq users + rabbitmq_user: + name: "{{ item.name }}" + password: "{{ item.password }}" + vhost: "{{ item.vhost }}" + configure_priv: "{{ item.configure_priv }}" + read_priv: "{{ item.read_priv }}" + write_priv: "{{ item.write_priv }}" + tags: "{{ item.tags }}" + state: present + run_once: yes + with_items: rabbitmq_users + when: (enable_rabbitmq_clustering is defined and enable_rabbitmq_clustering) -- cgit v1.2.3