From 109c6b750751d1c5cd216ad2f09258cf512c4c9e Mon Sep 17 00:00:00 2001 From: Larry Smith Jr Date: Sat, 3 Dec 2016 17:51:25 -0500 Subject: Addressed issue #6 Signed-off-by: Larry Smith Jr --- tasks/debian.yml | 35 ++++++++++++++++++++++ tasks/fedora.yml | 39 ++++++++++++++++++++++++ tasks/main.yml | 21 +++++++++++++ tasks/rabbitmq_clustering.yml | 70 +++++++++++++++++++++++++++++++++++++++++++ tasks/rabbitmq_ha_config.yml | 44 +++++++++++++++++++++++++++ tasks/rabbitmq_users.yml | 27 +++++++++++++++++ tasks/redhat.yml | 40 +++++++++++++++++++++++++ 7 files changed, 276 insertions(+) create mode 100644 tasks/debian.yml create mode 100644 tasks/fedora.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 tasks/rabbitmq_users.yml create mode 100644 tasks/redhat.yml (limited to 'tasks') diff --git a/tasks/debian.yml b/tasks/debian.yml new file mode 100644 index 0000000..a031ead --- /dev/null +++ b/tasks/debian.yml @@ -0,0 +1,35 @@ +--- +- name: debian | adding RabbitMQ public GPG key to the apt repo + apt_key: + url: "{{ rabbitmq_debian_repo_key }}" + state: present + +- name: debian | adding RabbitMQ repo + apt_repository: + repo: "{{ rabbitmq_debian_repo }}" + state: present + register: "rabbitmq_repo_added" + +- name: debian | updating apt cache + apt: + update_cache: yes + when: rabbitmq_repo_added.changed + +- name: debian | installing RabbitMQ server + apt: + name: "{{ item }}" + state: present + with_items: + - rabbitmq-server + +- name: debian | enabling the RabbitMQ Management Console + 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 diff --git a/tasks/fedora.yml b/tasks/fedora.yml new file mode 100644 index 0000000..3d92963 --- /dev/null +++ b/tasks/fedora.yml @@ -0,0 +1,39 @@ +--- +- name: fedora | installing pre-reqs + dnf: + name: "{{ item }}" + state: present + with_items: + - wget + +- name: fedora | installing erlang + dnf: + name: "erlang" + state: present + +- name: fedora | adding RabbitMQ public GPG key + rpm_key: + key: "{{ rabbitmq_redhat_repo_key }}" + state: present + +- name: fedora | downloading RabbitMQ + get_url: + url: "{{ rabbitmq_redhat_url }}/{{ rabbitmq_redhat_package }}" + dest: "/opt/{{ rabbitmq_redhat_package }}" + +- name: fedora | installing RabbitMQ + dnf: + name: "/opt/{{ rabbitmq_redhat_package }}" + state: present + +- name: fedora | starting and enabling RabbitMQ service + service: + name: "rabbitmq-server" + state: started + enabled: yes + +- name: fedora | enabling the RabbitMQ Management Console + rabbitmq_plugin: + names: rabbitmq_management + state: enabled + notify: restart rabbitmq-server diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..bd82f93 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,21 @@ +# tasks file for ansible-rabbitmq +- include: debian.yml + when: ansible_os_family == "Debian" + +- include: redhat.yml + when: ansible_distribution == "CentOS" or ansible_distribution == "Red Hat Enterprise Linux" + +- include: fedora.yml + when: ansible_distribution == "Fedora" + +- name: checking to see if already clustered + stat: path=/etc/rabbitmq/clustered + register: clustered + +- include: rabbitmq_clustering.yml + when: rabbitmq_enable_clustering and (clustered.stat.exists != True) + +- include: rabbitmq_ha_config.yml + when: rabbitmq_config_ha and rabbitmq_enable_clustering + +- include: rabbitmq_users.yml diff --git a/tasks/rabbitmq_clustering.yml b/tasks/rabbitmq_clustering.yml new file mode 100644 index 0000000..9dece46 --- /dev/null +++ b/tasks/rabbitmq_clustering.yml @@ -0,0 +1,70 @@ +--- +- name: rabbitmq_clustering | stopping rabbitmq app + command: rabbitmqctl stop_app + +- name: rabbitmq_clustering | resetting rabbitmq app + command: rabbitmqctl reset + +- name: rabbitmq_clustering | stopping rabbitmq-server + service: + name: rabbitmq-server + state: stopped + +#- name: grabbing erlang cookie +# shell: cat /var/lib/rabbitmq/.erlang.cookie +# register: rabbitmq_erlang_cookie +# when: inventory_hostname == "{{ rabbitmq_master }}" + +- name: rabbitmq_clustering | copy erlang cookie + template: + src: erlang.cookie.j2 + dest: "{{ rabbitmq_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 + when: inventory_hostname == "{{ rabbitmq_master }}" + +- name: rabbitmq_clustering | starting rabbitmq app on master + command: rabbitmqctl start_app + register: cluster_master + when: inventory_hostname == "{{ rabbitmq_master }}" + +- name: rabbitmq_clustering | sending sigterm to any running rabbitmq processes + shell: pkill -u rabbitmq || true + when: inventory_hostname != "{{ rabbitmq_master }}" + +- name: rabbitmq_clustering | restarting rabbitmq-server + service: + name: rabbitmq-server + state: restarted + when: inventory_hostname != "{{ rabbitmq_master }}" + +- name: rabbitmq_clustering | stopping rabbitmq app + command: rabbitmqctl stop_app + when: inventory_hostname != "{{ rabbitmq_master }}" + +- name: rabbitmq_clustering | resetting rabbitmq app + command: rabbitmqctl reset + when: inventory_hostname != "{{ rabbitmq_master }}" + +- name: rabbitmq_clustering | joining rabbitmq cluster + command: rabbitmqctl join_cluster 'rabbit@{{ rabbitmq_master }}' + register: cluster_joined + when: inventory_hostname != "{{ rabbitmq_master }}" + +- name: rabbitmq_clustering | starting rabbitmq app + command: rabbitmqctl start_app + when: inventory_hostname != "{{ rabbitmq_master }}" + +- name: rabbitmq_clustering | marking as clustered + 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 new file mode 100644 index 0000000..8811b6d --- /dev/null +++ b/tasks/rabbitmq_ha_config.yml @@ -0,0 +1,44 @@ +--- +- 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: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 }} + run_once: true + 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 + run_once: true + with_items: "{{ rabbitmq_config }}" + +- 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 }}" + 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..8bce8b2 --- /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: (rabbitmq_enable_clustering is defined and not rabbitmq_enable_clustering) or rabbitmq_enable_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: (rabbitmq_enable_clustering is defined and rabbitmq_enable_clustering) diff --git a/tasks/redhat.yml b/tasks/redhat.yml new file mode 100644 index 0000000..484597d --- /dev/null +++ b/tasks/redhat.yml @@ -0,0 +1,40 @@ +--- +- name: redhat | installing pre-reqs + yum: + name: "{{ item }}" + state: present + with_items: + - epel-release + - wget + +- name: redhat | installing erlang + yum: + name: "erlang" + state: present + +- name: redhat | adding RabbitMQ public GPG key + rpm_key: + key: "{{ rabbitmq_redhat_repo_key }}" + state: present + +- name: redhat | downloading RabbitMQ + get_url: + url: "{{ rabbitmq_redhat_url }}/{{ rabbitmq_redhat_package }}" + dest: "/opt/{{ rabbitmq_redhat_package }}" + +- name: redhat | installing RabbitMQ + yum: + name: "/opt/{{ rabbitmq_redhat_package }}" + state: present + +- name: redhat | starting and enabling RabbitMQ service + service: + name: "rabbitmq-server" + state: started + enabled: yes + +- name: redhat | enabling the RabbitMQ Management Console + rabbitmq_plugin: + names: rabbitmq_management + state: enabled + notify: restart rabbitmq-server -- cgit v1.2.3