--- /dev/null
+Role Name
+=========
+
+Installs rabbitmq https://www.rabbitmq.com/ (Configurable...HA and Clustering ready)
+
+Requirements
+------------
+
+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
+````
+
+Dependencies
+------------
+
+None
+
+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:
+````
+
+License
+-------
+
+BSD
+
+Author Information
+------------------
+
+Larry Smith Jr.
+- @mrlesmithjr
+- http://everythingshouldbevirtual.com
+- mrlesmithjr [at] gmail.com
--- /dev/null
+# -*- mode: ruby -*-
+# vi: set ft=ruby :
+
+# All Vagrant configuration is done below. The "2" in Vagrant.configure
+# configures the configuration version (we support older styles for
+# backwards compatibility). Please don't change it unless you know what
+# you're doing.
+
+# ---- Define number of nodes to spin up ----
+N = 3
+
+# ---- Define any custom memory/cpu requirement ----
+# if custom requirements are desired...ensure to set
+# custom_cpu_mem == true otherwise set to false
+# By default if custom requirements are defined and set below
+# any node not defined will be configured as the default...
+# which is 1vCPU/512mb...So if setting custom requirements
+# only define any node which requires more than the defaults.
+nodes = [
+ {
+ :node => "node0",
+ :box => "mrlesmithjr/trusty64",
+ :cpu => 1,
+ :mem => 1024
+ }
+]
+
+# ---- Define variables below ----
+#Define if additional disks should be added (true|false)
+additional_disks = false
+additional_disks_controller = "SATA Controller"
+#Define the number of additional disks to add
+additional_disks_num = 1
+#Define disk size in GB
+additional_disks_size = 10
+#Define if additional network adapters should be created (true|false)
+additional_nics = true
+#Define if add'l network adapters are auto configured addresses (true|false)
+additional_nics_auto_config = true
+#Define if additional network adapters should be DHCP assigned (true|false)
+additional_nics_dhcp = false
+#Define the number of additional nics to add
+additional_nics_num = 1
+ansible_groups = {
+ "test-nodes" => ["node[0:#{N-1}]"]
+}
+#Define Vagrant box to load
+box = "ubuntu/trusty64"
+#Define if custom cpu and memory requirements are needed (true|false)
+ #defined within nodes variable above
+custom_cpu_mem = false
+#Define if running desktop OS (true|false)
+desktop = false
+#Define if custom boxes should be used...defined in nodes var..
+enable_custom_boxes = false
+#Define if port forwards should be enabled (true|false)
+enable_port_forwards = false
+#Defines if nodes should be linked from master VM (true|false)
+linked_clones = false
+port_forwards = [
+ {
+ :node => "node0",
+ :guest => 3306,
+ :host => 3306
+ },
+ {
+ :node => "node0",
+ :guest => 80,
+ :host => 8080
+ },
+ {
+ :node => "node0",
+ :guest => 8000,
+ :host => 8000
+ }
+]
+#Define if provisioners should run (true|false)
+provision_nodes = true
+#Define if IP's are random assigned if not DHCP (true|false)
+random_ips = false
+#Define number of CPU cores
+ #will be ignored if custom_cpu_mem == true
+server_cpus = 1
+#Define amount of memory to assign to node(s)
+ #will be ignored if custom_cpu_mem == true
+server_memory = 512
+#Define subnet for private_network (If not using DHCP)
+subnet = "192.168.202."
+#Define starting last octet of the subnet range to begin addresses for node(s)
+subnet_ip_start = 200
+
+Vagrant.configure(2) do |config|
+
+ #Iterate over nodes
+ (1..N).each do |node_id|
+ nid = (node_id - 1)
+
+ config.vm.define "node#{nid}" do |node|
+ if enable_custom_boxes
+ #Initially no so it can be set to yes if found in custom box defined
+ box_set = "no"
+ nodes.each do |cust_box|
+ if cust_box[:node] == "node#{nid}"
+ node.vm.box = cust_box[:box]
+ box_set = "yes"
+ end
+ end
+ if box_set == "no"
+ node.vm.box = box
+ end
+ end
+ if not enable_custom_boxes
+ node.vm.box = box
+ end
+ node.vm.provider "virtualbox" do |vb|
+ if linked_clones
+ vb.linked_clone = true
+ end
+ if not custom_cpu_mem
+ vb.customize ["modifyvm", :id, "--cpus", server_cpus]
+ vb.customize ["modifyvm", :id, "--memory", server_memory]
+ end
+ if custom_cpu_mem
+ nodes.each do |cust_node|
+ if cust_node[:node] == "node#{nid}"
+ vb.customize ["modifyvm", :id, "--cpus", cust_node[:cpu]]
+ vb.customize ["modifyvm", :id, "--memory", cust_node[:mem]]
+ end
+ end
+ end
+
+ # Setup desktop environment
+ if desktop
+ vb.gui = true
+ vb.customize ["modifyvm", :id, "--graphicscontroller", "vboxvga"]
+ vb.customize ["modifyvm", :id, "--accelerate3d", "on"]
+ vb.customize ["modifyvm", :id, "--ioapic", "on"]
+ vb.customize ["modifyvm", :id, "--vram", "128"]
+ vb.customize ["modifyvm", :id, "--hwvirtex", "on"]
+ end
+
+ # Add additional disks
+ if additional_disks
+ (1..additional_disks_num).each do |disk_num|
+ dnum = (disk_num + 1)
+ ddev = ("node#{nid}_Disk#{dnum}.vdi")
+ unless File.exist?("#{ddev}")
+ vb.customize ['createhd', '--filename', ("#{ddev}"), \
+ '--variant', 'Fixed', '--size', additional_disks_size * 1024]
+ end
+ vb.customize ['storageattach', :id, '--storagectl', \
+ "#{additional_disks_controller}", '--port', dnum, '--device', 0, \
+ '--type', 'hdd', '--medium', "node#{nid}_Disk#{dnum}.vdi"]
+ end
+ end
+ end
+ node.vm.hostname = "node#{nid}"
+
+ # Define additional network adapters below
+ if additional_nics
+ if not additional_nics_dhcp
+ (1..additional_nics_num).each do |nic_num|
+ if random_ips
+ nnum = Random.rand(0..50)
+ if additional_nics_auto_config
+ node.vm.network :private_network, \
+ ip: subnet+"#{subnet_ip_start + nid + nnum}"
+ end
+ if not additional_nics_auto_config
+ node.vm.network :private_network, \
+ ip: subnet+"#{subnet_ip_start + nid + nnum}",
+ auto_config: false
+ end
+ end
+ if not random_ips
+ if additional_nics_auto_config
+ node.vm.network :private_network, \
+ ip: subnet+"#{subnet_ip_start + nid}"
+ end
+ if not additional_nics_auto_config
+ node.vm.network :private_network, \
+ ip: subnet+"#{subnet_ip_start + nid}",
+ auto_config: false
+ end
+ end
+ end
+ end
+ if additional_nics_dhcp
+ (1..additional_nics_num).each do |nic_num|
+ node.vm.network :private_network, type: "dhcp"
+ end
+ end
+ end
+
+ # Define port forwards below
+ if enable_port_forwards
+ port_forwards.each do |pf|
+ if pf[:node] == "node#{nid}"
+ node.vm.network :forwarded_port, guest: pf[:guest], \
+ host: pf[:host]
+ end
+ end
+ end
+
+ # Provisioners
+ if provision_nodes
+ if node_id == N
+ node.vm.provision "ansible" do |ansible|
+ ansible.limit = "all"
+ #runs bootstrap Ansible playbook
+ ansible.playbook = "bootstrap.yml"
+ end
+ node.vm.provision "ansible" do |ansible|
+ ansible.limit = "all"
+ #runs Ansible playbook for installing roles/executing tasks
+ ansible.playbook = "playbook.yml"
+ ansible.groups = ansible_groups
+ end
+ end
+ end
+
+ end
+ end
+ if provision_nodes
+ #runs initial shell script
+ config.vm.provision :shell, path: "bootstrap.sh", keep_color: "true"
+ end
+end
--- /dev/null
+#!/bin/bash
+if [ -f /etc/debian_version ]; then
+ codename="$(lsb_release -c | awk {'print $2}')"
+ if [[ $codename == "vivid" ]]; then
+ sudo apt-get update && \
+ sudo apt-get -y install python-simplejson
+ fi
+ if [[ $codename == "wily" ]]; then
+ sudo apt-get update && \
+ sudo apt-get -y install python-simplejson
+ fi
+ if [[ $codename == "xenial" ]]; then
+ sudo apt-get update && \
+ sudo apt-get -y install python-simplejson
+ fi
+fi
+if [ -f /etc/redhat-release ]; then
+ codename="$(gawk -F= '/^NAME/{print $2}' /etc/os-release)"
+ if [[ $codename == "Fedora" ]]; then
+ sudo dnf -y install python-devel python-dnf && \
+ sudo dnf -y group install "C Development Tools and Libraries"
+ fi
+fi
--- /dev/null
+---
+- hosts: all
+ remote_user: vagrant
+ become: true
+ vars:
+ - host_vars_directory: './host_vars'
+ - host_vars_file: '{{ host_vars_directory }}/{{ inventory_hostname }}.yml'
+ - pri_domain_name: 'vagrant.local'
+ - ssh_key_path: '.vagrant/machines/{{ inventory_hostname }}/virtualbox/private_key'
+ - update_host_vars: true
+ roles:
+ tasks:
+ - name: updating apt cache (Debian)
+ apt:
+ update_cache: yes
+ cache_valid_time: 3600
+ when: ansible_os_family == "Debian"
+
+ - name: installing ansible pre-reqs (Debian)
+ apt:
+ name: "{{ item }}"
+ state: present
+ with_items:
+ - libffi-dev
+ - libssl-dev
+ - python-dev
+ - python-setuptools
+ when: >
+ ansible_os_family == "Debian"
+
+ - name: installing epel repo (RedHat)
+ yum:
+ name: "epel-release"
+ state: present
+ when: >
+ ansible_os_family == "RedHat" and
+ ansible_distribution != "Fedora"
+
+ - name: installing ansible pre-reqs (RedHat)
+ yum:
+ name: "{{ item }}"
+ state: present
+ with_items:
+ - libffi-devel
+ - openssl-devel
+ - python-crypto
+ - python-devel
+ - python-setuptools
+ when: >
+ ansible_os_family == "RedHat" and
+ ansible_distribution != "Fedora"
+
+ - name: installing ansible pre-reqs (Fedora)
+ dnf:
+ name: "{{ item }}"
+ state: present
+ with_items:
+ - gmp-devel
+ - libffi-devel
+ - openssl-devel
+ - python-crypto
+ - python-devel
+ - python-dnf
+ - python-setuptools
+ - redhat-rpm-config
+ when: >
+ ansible_os_family == "RedHat" and
+ ansible_distribution == "Fedora"
+
+ - name: installing ansible pre-reqs (openSUSE)
+ zypper:
+ name: "{{ item }}"
+ state: present
+ with_items:
+ - gmp-devel
+ - libffi-devel
+ - openssl-devel
+ - python-crypto
+ - python-devel
+ - python-setuptools
+ when: >
+ ansible_os_family == "openSUSE Leap"
+
+ - name: installing python pip
+ easy_install:
+ name: "pip"
+ state: present
+
+ - name: installing ansible
+ pip:
+ name: "ansible"
+ state: present
+ version: 1.9.6
+
+ - name: ensuring host_vars directory exists
+ file:
+ path: "./host_vars"
+ state: directory
+ delegate_to: localhost
+ run_once: true
+ become: false
+ when: update_host_vars is defined and update_host_vars
+
+ - name: ensuring host file exists in host_vars
+ stat:
+ path: "{{ host_vars_file }}"
+ delegate_to: localhost
+ register: host_var
+ become: false
+ when: >
+ update_host_vars is defined and
+ update_host_vars
+
+ - name: creating missing host_vars
+ file:
+ path: "{{ host_vars_file }}"
+ state: touch
+ delegate_to: localhost
+ become: false
+ when: not host_var.stat.exists
+
+ - name: updating ansible_ssh_port
+ lineinfile:
+ dest: "{{ host_vars_file }}"
+ regexp: "^ansible_ssh_port{{ ':' }}"
+ line: "ansible_ssh_port{{ ':' }} 22"
+ delegate_to: localhost
+ become: false
+ when: >
+ (update_host_vars is defined and
+ update_host_vars) and
+ (ansible_eth1 is defined or
+ ansible_enp0s8 is defined)
+
+ - name: updating ansible_ssh_host
+ lineinfile:
+ dest: "{{ host_vars_file }}"
+ regexp: "^ansible_ssh_host{{ ':' }}"
+ line: "ansible_ssh_host{{ ':' }} {{ ansible_eth1.ipv4.address }}"
+ delegate_to: localhost
+ become: false
+ when: >
+ (update_host_vars is defined and
+ update_host_vars) and
+ ansible_eth1 is defined
+
+ - name: updating ansible_ssh_host
+ lineinfile:
+ dest: "{{ host_vars_file }}"
+ regexp: "^ansible_ssh_host{{ ':' }}"
+ line: "ansible_ssh_host{{ ':' }} {{ ansible_enp0s8.ipv4.address }}"
+ delegate_to: localhost
+ become: false
+ when: >
+ (update_host_vars is defined and
+ update_host_vars) and
+ ansible_enp0s8 is defined
+
+ - name: updating ansible_ssh_key
+ lineinfile:
+ dest: "{{ host_vars_file }}"
+ regexp: "^ansible_ssh_private_key_file{{ ':' }}"
+ line: "ansible_ssh_private_key_file{{ ':' }} {{ ssh_key_path }}"
+ delegate_to: localhost
+ become: false
+ when: >
+ update_host_vars is defined and
+ update_host_vars
+
+ - name: ensuring host_vars is yaml formatted
+ lineinfile:
+ dest: "{{ host_vars_file }}"
+ regexp: "---"
+ line: "---"
+ insertbefore: BOF
+ delegate_to: localhost
+ become: false
+ when: >
+ update_host_vars is defined and
+ update_host_vars
--- /dev/null
+#!/bin/bash
+vagrant destroy -f
+if [ -d host_vars ]; then
+ rm -rf host_vars
+fi
+if [ -d .vagrant ]; then
+ rm -rf .vagrant
+fi
--- /dev/null
+../playbook.yml
\ No newline at end of file
--- /dev/null
+../requirements.yml
\ No newline at end of file
--- /dev/null
+Role Name
+=========
+
+Installs rabbitmq https://www.rabbitmq.com/ (Configurable...HA and Clustering ready)
+
+Requirements
+------------
+
+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
+````
+
+Dependencies
+------------
+
+None
+
+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:
+````
+
+License
+-------
+
+BSD
+
+Author Information
+------------------
+
+Larry Smith Jr.
+- @mrlesmithjr
+- http://everythingshouldbevirtual.com
+- mrlesmithjr [at] gmail.com
--- /dev/null
+# -*- mode: ruby -*-
+# vi: set ft=ruby :
+
+# All Vagrant configuration is done below. The "2" in Vagrant.configure
+# configures the configuration version (we support older styles for
+# backwards compatibility). Please don't change it unless you know what
+# you're doing.
+Vagrant.configure(2) do |config|
+ #Define if running desktop OS to yes otherwise no
+ Desktop = "no"
+ #Define the number of nodes to spin up
+ N = 3
+
+ #Iterate over nodes
+ (1..N).each do |node_id|
+ nid = (node_id - 1)
+
+ config.vm.define "node#{nid}" do |node|
+ node.vm.box = "mrlesmithjr/centos-7"
+ node.vm.provider "virtualbox" do |vb|
+ vb.memory = "1024"
+ vb.cpus = "1"
+ if Desktop == "yes"
+ vb.gui = true
+ vb.customize ["modifyvm", :id, "--graphicscontroller", "vboxvga"]
+ vb.customize ["modifyvm", :id, "--accelerate3d", "on"]
+ vb.customize ["modifyvm", :id, "--ioapic", "on"]
+ vb.customize ["modifyvm", :id, "--vram", "128"]
+ vb.customize ["modifyvm", :id, "--hwvirtex", "on"]
+ end
+ end
+ node.vm.hostname = "node#{nid}"
+ ### Define additional network adapters below
+ node.vm.network :private_network, ip: "192.168.202.#{200 + nid}"
+
+ ### Define port forwards below
+# node.vm.network "forwarded_port", guest: 80, host: "#{8080 + nid}"
+# node.vm.network "forwarded_port", guest: 3000, host: "#{3000 + nid}"
+
+ if node_id == N
+ node.vm.provision :shell, path: "bootstrap.sh", keep_color: "true" #runs initial shell script
+ node.vm.provision "ansible" do |ansible| #runs bootstrap Ansible playbook
+ ansible.limit = "all"
+ ansible.playbook = "bootstrap.yml"
+ end
+ node.vm.provision "ansible" do |ansible| #runs Ansible playbook for installing roles/executing tasks
+ ansible.limit = "all"
+ ansible.playbook = "playbook.yml"
+ ansible.groups = {
+ "test-nodes" => [
+ "node0",
+ "node1"
+ ],
+ "prod-nodes" => [
+ "node2"
+ ]
+ }
+ end
+ end
+
+ end
+ end
+end
--- /dev/null
+[defaults]
+host_key_checking = False
+#roles_path = ../
--- /dev/null
+#!/bin/bash
+if [ -f /etc/debian_version ]; then
+ codename="$(lsb_release -c | awk {'print $2}')"
+ if [ $codename == "vivid" ]; then
+ sudo apt-get update && sudo apt-get -y install python-simplejson
+ fi
+fi
+if [ -f /etc/redhat-release ]; then
+ codename="$(gawk -F= '/^NAME/{print $2}' /etc/os-release)"
+ if [ $codename == "Fedora" ]; then
+ sudo dnf -y install python-devel python-dnf python-pip && \
+ sudo dnf -y group install "C Development Tools and Libraries"
+ fi
+fi
--- /dev/null
+---
+- hosts: all
+ remote_user: vagrant
+ become: true
+ vars:
+ - host_vars_directory: './host_vars'
+ - host_vars_file: '{{ host_vars_directory }}/{{ inventory_hostname }}.yml'
+ - pri_domain_name: 'vagrant.local'
+ - ssh_key_path: '.vagrant/machines/{{ inventory_hostname }}/virtualbox/private_key'
+ - update_host_vars: true
+ roles:
+ tasks:
+ - name: updating apt cache (Debian)
+ apt:
+ update_cache: yes
+ cache_valid_time: 3600
+ when: ansible_os_family == "Debian"
+
+ - name: installing ansible pre-reqs (Debian)
+ apt:
+ name: "{{ item }}"
+ state: present
+ with_items:
+ - python-dev
+ - python-pip
+ when: ansible_os_family == "Debian"
+
+ - name: installing epel repo (RedHat)
+ yum:
+ name: "epel-release"
+ state: present
+ when: >
+ ansible_os_family == "RedHat" and
+ ansible_distribution != "Fedora"
+
+ - name: installing ansible pre-reqs (RedHat)
+ yum:
+ name: "{{ item }}"
+ state: present
+ with_items:
+ - python-devel
+ - python-dnf
+ - python-pip
+ when: >
+ ansible_os_family == "RedHat" and
+ ansible_distribution != "Fedora"
+
+ - name: installing ansible pre-reqs (Fedora)
+ dnf:
+ name: "{{ item }}"
+ state: present
+ with_items:
+ - gmp-devel
+ - python-crypto
+ - python-devel
+ - python-dnf
+ - python-pip
+ when: >
+ ansible_os_family == "RedHat" and
+ ansible_distribution == "Fedora"
+
+ - name: installing ansible
+ pip:
+ name: "ansible"
+ state: present
+
+ - name: ensuring host_vars directory exists
+ file:
+ path: "./host_vars"
+ state: directory
+ delegate_to: localhost
+ run_once: true
+ become: false
+ when: update_host_vars is defined and update_host_vars
+
+ - name: ensuring host file exists in host_vars
+ stat:
+ path: "{{ host_vars_file }}"
+ delegate_to: localhost
+ register: host_var
+ become: false
+ when: >
+ update_host_vars is defined and
+ update_host_vars
+
+ - name: creating missing host_vars
+ file:
+ path: "{{ host_vars_file }}"
+ state: touch
+ delegate_to: localhost
+ become: false
+ when: not host_var.stat.exists
+
+ - name: updating ansible_ssh_port
+ lineinfile:
+ dest: "{{ host_vars_file }}"
+ regexp: "^ansible_ssh_port{{ ':' }}"
+ line: "ansible_ssh_port{{ ':' }} 22"
+ delegate_to: localhost
+ become: false
+ when: >
+ (update_host_vars is defined and
+ update_host_vars) and
+ (ansible_eth1 is defined or
+ ansible_enp0s8 is defined)
+
+ - name: updating ansible_ssh_host
+ lineinfile:
+ dest: "{{ host_vars_file }}"
+ regexp: "^ansible_ssh_host{{ ':' }}"
+ line: "ansible_ssh_host{{ ':' }} {{ ansible_eth1.ipv4.address }}"
+ delegate_to: localhost
+ become: false
+ when: >
+ (update_host_vars is defined and
+ update_host_vars) and
+ ansible_eth1 is defined
+
+ - name: updating ansible_ssh_host
+ lineinfile:
+ dest: "{{ host_vars_file }}"
+ regexp: "^ansible_ssh_host{{ ':' }}"
+ line: "ansible_ssh_host{{ ':' }} {{ ansible_enp0s8.ipv4.address }}"
+ delegate_to: localhost
+ become: false
+ when: >
+ (update_host_vars is defined and
+ update_host_vars) and
+ ansible_enp0s8 is defined
+
+ - name: updating ansible_ssh_key
+ lineinfile:
+ dest: "{{ host_vars_file }}"
+ regexp: "^ansible_ssh_private_key_file{{ ':' }}"
+ line: "ansible_ssh_private_key_file{{ ':' }} {{ ssh_key_path }}"
+ delegate_to: localhost
+ become: false
+ when: >
+ update_host_vars is defined and
+ update_host_vars
+
+ - name: ensuring host_vars is yaml formatted
+ lineinfile:
+ dest: "{{ host_vars_file }}"
+ regexp: "---"
+ line: "---"
+ insertbefore: BOF
+ delegate_to: localhost
+ become: false
+ when: >
+ update_host_vars is defined and
+ update_host_vars
--- /dev/null
+#!/bin/bash
+vagrant destroy -f
+if [ -d host_vars ]; then
+ rm -rf host_vars
+fi
+if [ -d .vagrant ]; then
+ rm -rf .vagrant
+fi
--- /dev/null
+---
+# 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_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
+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_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
--- /dev/null
+---
+# handlers file for ansible-rabbitmq
+- name: restart rabbitmq-server
+ service:
+ name: "rabbitmq-server"
+ state: restarted
--- /dev/null
+---
+galaxy_info:
+ author: Larry Smith Jr.
+ description: Installs rabbitmq https://www.rabbitmq.com/ (Configurable...HA and Clustering ready)
+ #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
+ - 23
+ #- 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.
--- /dev/null
+---
+- 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:
--- /dev/null
+---
+- src: https://github.com/mrlesmithjr/ansible-rabbitmq.git
--- /dev/null
+---
+- 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
--- /dev/null
+---
+- 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
--- /dev/null
+# 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
--- /dev/null
+---
+- 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
--- /dev/null
+---
+- 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
--- /dev/null
+---
+- 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)
--- /dev/null
+---
+- 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
--- /dev/null
+{{ rabbitmq_erlang_cookie }}
--- /dev/null
+---
+# vars file for ansible-rabbitmq
--- /dev/null
+[defaults]
+host_key_checking = False
+#roles_path = ../
--- /dev/null
+---
+# 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_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
+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_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
--- /dev/null
+---
+# handlers file for ansible-rabbitmq
+- name: restart rabbitmq-server
+ service:
+ name: "rabbitmq-server"
+ state: restarted
--- /dev/null
+---
+galaxy_info:
+ author: Larry Smith Jr.
+ description: Installs rabbitmq https://www.rabbitmq.com/ (Configurable...HA and Clustering ready)
+ #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
+ - 23
+ #- 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.
--- /dev/null
+---
+- 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:
+ pri_domain_name: 'test.vagrant.local'
+ rabbitmq_config_ha: true
+ rabbitmq_enable_clustering: true
+ rabbitmq_master: 'node0'
+ roles:
+ - role: ansible-rabbitmq
+ tasks:
--- /dev/null
+---
+- src: https://github.com/mrlesmithjr/ansible-rabbitmq.git
--- /dev/null
+---
+- 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
--- /dev/null
+---
+- 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
--- /dev/null
+# 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
--- /dev/null
+---
+- 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
--- /dev/null
+---
+- 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
--- /dev/null
+---
+- 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)
--- /dev/null
+---
+- 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
--- /dev/null
+{{ rabbitmq_erlang_cookie }}
--- /dev/null
+---
+# vars file for ansible-rabbitmq