Role Name
=========
-Installs rabbitmq https://www.rabbitmq.com/ (Configurable...HA and Clustering ready)
+An [Ansible] role to install/configure [RabbitMQ]
Build Status
------------
Requirements
------------
-Ensure hostnames are resolvable prior to clustering...either update /etc/hosts or ensure DNS is working.
+Ensure hostnames are resolvable prior to clustering...either update /etc/hosts
+or ensure DNS is working.
Vagrant
-------
Spin up a 3 node HA Cluster for testing...
Install Ansible role on your host:
-````
+```
sudo ansible-galaxy install -r requirements.yml -f
-````
+```
Now spin up your environment...
-````
+```
vagrant up
-````
+```
When you are done testing, tear it all down...
-````
+```
./cleanup.sh
-````
+```
Role Variables
--------------
-````
----
-# defaults file for ansible-rabbitmq
-rabbitmq_config_ha: false #defines if rabbitmq ha should be configured...define here or in group_vars/group
-rabbitmq_enable_clustering: false #defines if setting up a rabbitmq cluster...define here or in group_vars/group
-rabbitmq_erlang_cookie: 'LSKNKBELKPSTDBBCHETL' #define erlang cookie for cluster...define here or in group_vars/group
-rabbitmq_erlang_cookie_file: '/var/lib/rabbitmq/.erlang.cookie'
-rabbitmq_config:
- - queue_name: logstash
- durable: true
- exchange_name: logstash
- type: direct
- routing_key: logstash
- tags: 'ha-mode=all,ha-sync-mode=automatic'
-rabbitmq_debian_repo: 'deb http://www.rabbitmq.com/debian/ testing main'
-rabbitmq_debian_repo_key: 'http://www.rabbitmq.com/rabbitmq-signing-key-public.asc'
-rabbitmq_master: [] #defines the inventory host that should be considered master...define here or in group_vars/group
-rabbitmq_redhat_repo_key: 'https://www.rabbitmq.com/rabbitmq-signing-key-public.asc'
-rabbitmq_redhat_package: 'rabbitmq-server-{{ rabbitmq_redhat_version }}-1.noarch.rpm'
-rabbitmq_redhat_url: 'http://www.rabbitmq.com/releases/rabbitmq-server/v{{ rabbitmq_redhat_version }}'
-rabbitmq_redhat_version: '3.6.1'
-rabbitmq_users: #define admin user to create in order to login to WebUI
- - name: rabbitmqadmin
- password: rabbitmqadmin
- vhost: /
- configure_priv: '.*'
- read_priv: '.*'
- write_priv: '.*'
- tags: 'administrator' #define comma separated list of tags to assign to user....management,policymaker,monitoring,administrator...required for management plugin. https://www.rabbitmq.com/management.html
-````
-
-example...
-group_vars/rabbitmq-cluster-nodes
-````
----
-rabbitmq_enable_clustering: true
-rabbitmq_config_ha: false
-rabbitmq_master: ans-test-1
-````
+[Role Defaults](./defaults/main.yml)
Dependencies
------------
Example Playbook
----------------
-````
----
-- hosts: all
- become: true
- vars:
- - pri_domain_name: 'test.vagrant.local'
- roles:
- tasks:
- - name: updating /etc/hosts
- lineinfile:
- dest: /etc/hosts
- regexp: "^{{ hostvars[item].ansible_ssh_host }} {{ item }} {{ item }}.{{ pri_domain_name }}"
- line: "{{ hostvars[item].ansible_ssh_host }} {{ item }} {{ item }}.{{ pri_domain_name }}"
- state: present
- with_items: "{{ groups['all'] }}"
-
-- hosts: all
- become: true
- vars:
- - rabbitmq_config_ha: true
- - rabbitmq_enable_clustering: true
- - pri_domain_name: 'test.vagrant.local'
- - rabbitmq_master: 'node0'
- roles:
- - role: ansible-rabbitmq
- tasks:
-````
+[Example Playbook](./playbook.yml)
License
-------
------------------
Larry Smith Jr.
-- @mrlesmithjr
+- [@mrlesmithjr]
- http://everythingshouldbevirtual.com
- mrlesmithjr [at] gmail.com
+
+[@mrlesmithjr]: <https://www.twitter.com/mrlesmithjr>
+
+[Ansible]: <https://www.ansible.com>
+[RabbitMQ]: <https://www.rabbitmq.com/>
---
# defaults file for ansible-rabbitmq
-rabbitmq_config:
- - queue_name: 'logstash'
- durable: true
- exchange_name: logstash
- type: 'direct'
- routing_key: 'logstash'
- tags: 'ha-mode=all,ha-sync-mode=automatic'
-rabbitmq_config_ha: false #defines if rabbitmq ha should be configured...define here or in group_vars/group
+rabbitmq_config: []
+ # - queue_name: 'logstash'
+ # durable: true
+ # exchange_name: logstash
+ # type: 'direct'
+ # routing_key: 'logstash'
+ # tags: 'ha-mode=all,ha-sync-mode=automatic'
+
+# Defines if rabbitmq ha should be configured
+rabbitmq_config_ha: false
+
+rabbitmq_config_service: false
+
rabbitmq_debian_repo: 'deb http://www.rabbitmq.com/debian/ testing main'
rabbitmq_debian_repo_key: 'https://www.rabbitmq.com/rabbitmq-release-signing-key.asc'
-rabbitmq_enable_clustering: false #defines if setting up a rabbitmq cluster...define here or in group_vars/group
-rabbitmq_erlang_cookie: 'LSKNKBELKPSTDBBCHETL' #define erlang cookie for cluster...define here or in group_vars/group
+
+# Defines if setting up a rabbitmq cluster
+rabbitmq_enable_clustering: false
+
rabbitmq_erlang_cookie_file: '/var/lib/rabbitmq/.erlang.cookie'
-rabbitmq_master: [] #defines the inventory host that should be considered master...define here or in group_vars/group
+
+rabbitmq_listen_port: 5672
+rabbitmq_listeners: []
+ # - '127.0.0.1'
+ # - '::1'
+
+# Defines the inventory host that should be considered master
+rabbitmq_master: []
+
rabbitmq_redhat_repo_key: 'https://www.rabbitmq.com/rabbitmq-signing-key-public.asc'
rabbitmq_redhat_package: 'rabbitmq-server-{{ rabbitmq_redhat_version }}-1.noarch.rpm'
rabbitmq_redhat_url: 'http://www.rabbitmq.com/releases/rabbitmq-server/v{{ rabbitmq_redhat_version }}'
rabbitmq_redhat_version: '3.6.1'
-rabbitmq_users: #define admin user to create in order to login to WebUI
+
+# Define admin user to create in order to login to WebUI
+rabbitmq_users:
- name: 'rabbitmqadmin'
password: 'rabbitmqadmin'
vhost: '/'
configure_priv: '.*'
read_priv: '.*'
write_priv: '.*'
- tags: 'administrator' #define comma separated list of tags to assign to user....management,policymaker,monitoring,administrator...required for management plugin. https://www.rabbitmq.com/management.html
+ # Define comma separated list of tags to assign to user:
+ # management,policymaker,monitoring,administrator
+ # required for management plugin.
+ # https://www.rabbitmq.com/management.html
+ tags: 'administrator'
service:
name: "rabbitmq-server"
state: restarted
+ become: true
apt_key:
url: "{{ rabbitmq_debian_repo_key }}"
state: present
+ become: true
- name: debian | adding RabbitMQ repo
apt_repository:
repo: "{{ rabbitmq_debian_repo }}"
state: present
register: "rabbitmq_repo_added"
+ become: true
- name: debian | updating apt cache
apt:
update_cache: yes
+ become: true
when: rabbitmq_repo_added.changed
- name: debian | installing RabbitMQ server
apt:
name: "{{ item }}"
state: present
+ become: true
with_items:
- rabbitmq-server
rabbitmq_plugin:
names: rabbitmq_management
state: enabled
+ become: true
notify: restart rabbitmq-server
- name: debian | ensuring that the RabbitMQ service is running
name: rabbitmq-server
state: started
enabled: yes
+ become: true
dnf:
name: "{{ item }}"
state: present
+ become: true
with_items:
- wget
dnf:
name: "erlang"
state: present
+ become: true
- name: fedora | adding RabbitMQ public GPG key
rpm_key:
key: "{{ rabbitmq_redhat_repo_key }}"
state: present
+ become: true
- name: fedora | downloading RabbitMQ
get_url:
url: "{{ rabbitmq_redhat_url }}/{{ rabbitmq_redhat_package }}"
dest: "/opt/{{ rabbitmq_redhat_package }}"
+ become: true
- name: fedora | installing RabbitMQ
dnf:
name: "/opt/{{ rabbitmq_redhat_package }}"
state: present
+ become: true
- name: fedora | starting and enabling RabbitMQ service
service:
name: "rabbitmq-server"
state: started
enabled: yes
+ become: true
- name: fedora | enabling the RabbitMQ Management Console
rabbitmq_plugin:
names: rabbitmq_management
state: enabled
notify: restart rabbitmq-server
+ become: true
when: ansible_os_family == "Debian"
- include: redhat.yml
- when: ansible_distribution == "CentOS" or ansible_distribution == "Red Hat Enterprise Linux"
+ when: >
+ ansible_distribution == "CentOS" or
+ ansible_distribution == "Red Hat Enterprise Linux"
- include: fedora.yml
when: ansible_distribution == "Fedora"
+- include: config.yml
+ when: rabbitmq_config_service
+
- 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)
+ when: >
+ rabbitmq_enable_clustering and
+ not clustered['stat']['exists']
- include: rabbitmq_ha_config.yml
- when: rabbitmq_config_ha and rabbitmq_enable_clustering
+ when: >
+ rabbitmq_config_ha and
+ rabbitmq_enable_clustering and
+ rabbitmq_config is defined
- include: rabbitmq_users.yml
+ when: rabbitmq_users is defined
- name: rabbitmq_ha_config | install rabbitMQ admin
shell: wget http://guest:guest@localhost:15672/cli/rabbitmqadmin
- when: not rabbitmqadmin_check.stat.exists
+ become: true
+ 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
+ become: true
+ 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
+ become: true
+ 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 }}
+ command: rabbitmqadmin declare queue name={{ item['queue_name'] }} durable={{ item['durable']|lower }}
run_once: true
+ become: 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 }}"
+ pattern: "{{ item['queue_name'] }}"
+ tags: "{{ item['tags'] }}"
state: present
run_once: true
+ become: true
with_items: "{{ rabbitmq_config }}"
- name: rabbitmq_ha_config | creating exchange(s)
- command: rabbitmqadmin declare exchange name={{ item.exchange_name }} type={{ item.type }}
+ command: rabbitmqadmin declare exchange name={{ item['exchange_name'] }} type={{ item['type'] }}
run_once: true
+ become: true
with_items: "{{ rabbitmq_config }}"
- when: item.exchange_name is defined
+ 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 }}
+ command: rabbitmqadmin declare binding source={{ item['exchange_name'] }} destination_type="queue" destination={{ item['queue_name'] }} routing_key={{ item['routing_key'] }}
run_once: true
+ become: true
with_items: "{{ rabbitmq_config }}"
- when: item.exchange_name is defined
+ when: item['exchange_name'] is 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 }}"
+ 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
+ become: true
with_items: "{{ rabbitmq_users }}"
- when: (rabbitmq_enable_clustering is defined and not rabbitmq_enable_clustering) or rabbitmq_enable_clustering is not defined
+ 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 }}"
+ 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
+ become: true
with_items: "{{ rabbitmq_users }}"
- when: (rabbitmq_enable_clustering is defined and rabbitmq_enable_clustering)
+ when: >
+ rabbitmq_enable_clustering is defined and
+ rabbitmq_enable_clustering
yum:
name: "{{ item }}"
state: present
+ become: true
with_items:
- epel-release
- wget
yum:
name: "erlang"
state: present
+ become: true
- name: redhat | adding RabbitMQ public GPG key
rpm_key:
key: "{{ rabbitmq_redhat_repo_key }}"
state: present
+ become: true
- name: redhat | downloading RabbitMQ
get_url:
url: "{{ rabbitmq_redhat_url }}/{{ rabbitmq_redhat_package }}"
dest: "/opt/{{ rabbitmq_redhat_package }}"
+ become: true
- name: redhat | installing RabbitMQ
yum:
name: "/opt/{{ rabbitmq_redhat_package }}"
state: present
+ become: true
- name: redhat | starting and enabling RabbitMQ service
service:
name: "rabbitmq-server"
state: started
enabled: yes
+ become: true
- name: redhat | enabling the RabbitMQ Management Console
rabbitmq_plugin:
names: rabbitmq_management
state: enabled
notify: restart rabbitmq-server
+ become: true