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 --- README.md | 44 ++++++++++++++ defaults/main.yml | 4 ++ handlers/main.yml | 4 ++ meta/main.yml | 136 ++++++++++++++++++++++++++++++++++++++++++ tasks/main.yml | 29 +++++++++ tasks/rabbitmq_clustering.yml | 40 +++++++++++++ tasks/rabbitmq_ha_config.yml | 30 ++++++++++ templates/erlang.cookie.j2 | 1 + vars/main.yml | 2 + 9 files changed, 290 insertions(+) create mode 100644 README.md create mode 100644 defaults/main.yml create mode 100644 handlers/main.yml create mode 100644 meta/main.yml create mode 100644 tasks/main.yml create mode 100644 tasks/rabbitmq_clustering.yml create mode 100644 tasks/rabbitmq_ha_config.yml create mode 100644 templates/erlang.cookie.j2 create mode 100644 vars/main.yml diff --git a/README.md b/README.md new file mode 100644 index 0000000..bc57b4c --- /dev/null +++ b/README.md @@ -0,0 +1,44 @@ +Role Name +========= + +Installs rabbitmq https://www.rabbitmq.com/ + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +```` +enable_rabbitmq_clustering: false #defines if setting up a rabbitmq cluster +config_rabbitmq_ha: false #defines if rabbitmq ha should be configured +```` + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: mrlesmithjr.rabbitmq } + +License +------- + +BSD + +Author Information +------------------ + +Larry Smith Jr. +- @mrlesmithjr +- http://everythingshouldbevirtual.com +- mrlesmithjr [at] gmail.com diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..8ca8a4f --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,4 @@ +--- +# defaults file for ansible-rabbitmq +enable_rabbitmq_clustering: false #defines if setting up a rabbitmq cluster +config_rabbitmq_ha: false #defines if rabbitmq ha should be configured diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..54a880b --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,4 @@ +--- +# handlers file for ansible-rabbitmq +- name: restart rabbitmq-server + service: name=rabbitmq-server state=restarted diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..0bbfc73 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,136 @@ +--- +galaxy_info: + author: Larry Smith Jr. + description: Installs rabbitmq + #company: your company (optional) + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + min_ansible_version: 1.2 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + # - 21 + # - 22 + #- name: Windows + # versions: + # - all + # - 2012R2 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + - name: Ubuntu + versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + - trusty + # - utopic + # - vivid + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - jessie + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + categories: + #- cloud + #- cloud:ec2 + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + - system + #- web +dependencies: [] + # List your role dependencies here, one per line. Only + # dependencies available via galaxy should be listed here. + # Be sure to remove the '[]' above if you add dependencies + # to this list. 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 diff --git a/templates/erlang.cookie.j2 b/templates/erlang.cookie.j2 new file mode 100644 index 0000000..cb398e7 --- /dev/null +++ b/templates/erlang.cookie.j2 @@ -0,0 +1 @@ +{{ erlang_cookie }} diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..5977bc8 --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for ansible-rabbitmq -- cgit v1.2.3