]> git.immae.eu Git - github/fretlink/ansible-rabbitmq.git/commitdiff
Added support for CentOS and Vagrant
authorLarry Smith Jr <mrlesmithjr@gmail.coml>
Thu, 3 Mar 2016 20:28:30 +0000 (15:28 -0500)
committerLarry Smith Jr <mrlesmithjr@gmail.coml>
Thu, 3 Mar 2016 20:28:30 +0000 (15:28 -0500)
Signed-off-by: Larry Smith Jr <mrlesmithjr@gmail.coml>
13 files changed:
README.md
Vagrantfile [new file with mode: 0644]
ansible.cfg [new file with mode: 0644]
bootstrap.sh [new file with mode: 0755]
bootstrap.yml [new file with mode: 0644]
cleanup.sh [new file with mode: 0755]
defaults/main.yml
handlers/main.yml
meta/main.yml
playbook.yml [new file with mode: 0644]
requirements.yml [new file with mode: 0644]
tasks/main.yml
tasks/redhat.yml [new file with mode: 0644]

index a4a7c45efa0b8b1791decf71aabdd61134b54dd8..8685452161300fc8ace4e08c4395a81279a17a8e 100644 (file)
--- a/README.md
+++ b/README.md
@@ -8,14 +8,33 @@ 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
 config_rabbitmq_ha: false  #defines if rabbitmq ha should be configured...define here or in group_vars/group
 enable_rabbitmq_clustering: false  #defines if setting up a rabbitmq cluster...define here or in group_vars/group
-erlang_cookie: LSKNKBELKPSTDBBCHETL  #define erlang cookie for cluster...define here or in group_vars/group
-erlang_cookie_file: /var/lib/rabbitmq/.erlang.cookie
+erlang_cookie: 'LSKNKBELKPSTDBBCHETL'  #define erlang cookie for cluster...define here or in group_vars/group
+erlang_cookie_file: '/var/lib/rabbitmq/.erlang.cookie'
 rabbitmq_config:
   - queue_name: logstash
     durable: true
@@ -23,7 +42,21 @@ rabbitmq_config:
     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...
@@ -38,16 +71,38 @@ rabbitmq_master: ans-test-1
 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.
+None
 
 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: 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: servers
-      roles:
-         - { role: mrlesmithjr.rabbitmq }
+- hosts: all
+  become: true
+  vars:
+    - config_rabbitmq_ha: true
+    - enable_rabbitmq_clustering: true
+    - pri_domain_name: 'test.vagrant.local'
+    - rabbitmq_master: 'node0'
+  roles:
+    - role: ansible-rabbitmq
+  tasks:
+````
 
 License
 -------
diff --git a/Vagrantfile b/Vagrantfile
new file mode 100644 (file)
index 0000000..9c68a3d
--- /dev/null
@@ -0,0 +1,63 @@
+# -*- 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
diff --git a/ansible.cfg b/ansible.cfg
new file mode 100644 (file)
index 0000000..5a1e589
--- /dev/null
@@ -0,0 +1,3 @@
+[defaults]
+host_key_checking = False
+#roles_path = ../
diff --git a/bootstrap.sh b/bootstrap.sh
new file mode 100755 (executable)
index 0000000..7bcf8b0
--- /dev/null
@@ -0,0 +1,14 @@
+#!/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
diff --git a/bootstrap.yml b/bootstrap.yml
new file mode 100644 (file)
index 0000000..702b540
--- /dev/null
@@ -0,0 +1,152 @@
+---
+- 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
diff --git a/cleanup.sh b/cleanup.sh
new file mode 100755 (executable)
index 0000000..a049429
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/bash
+vagrant destroy -f
+if [ -d host_vars ]; then
+  rm -rf host_vars
+fi
+if [ -d .vagrant ]; then
+  rm -rf .vagrant
+fi
index a8d37f4ec9a04d866363dbb4bb6f1c764c32ca88..65c00ba1823e1df20d269a036d55f7fd0b4c693e 100644 (file)
@@ -2,8 +2,8 @@
 # defaults file for ansible-rabbitmq
 config_rabbitmq_ha: false  #defines if rabbitmq ha should be configured...define here or in group_vars/group
 enable_rabbitmq_clustering: false  #defines if setting up a rabbitmq cluster...define here or in group_vars/group
-erlang_cookie: LSKNKBELKPSTDBBCHETL  #define erlang cookie for cluster...define here or in group_vars/group
-erlang_cookie_file: /var/lib/rabbitmq/.erlang.cookie
+erlang_cookie: 'LSKNKBELKPSTDBBCHETL'  #define erlang cookie for cluster...define here or in group_vars/group
+erlang_cookie_file: '/var/lib/rabbitmq/.erlang.cookie'
 rabbitmq_config:
   - queue_name: logstash
     durable: true
@@ -11,9 +11,13 @@ rabbitmq_config:
     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_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
index 54a880b706ed4e15e05579be4806b1be322e66f6..259ce1c2dfa0b544af150d6965f5585c73da519a 100644 (file)
@@ -1,4 +1,6 @@
 ---
 # handlers file for ansible-rabbitmq
 - name: restart rabbitmq-server
-  service: name=rabbitmq-server state=restarted
+  service:
+    name: "rabbitmq-server"
+    state: restarted
index 4bd090d86dba7adf0c1d3feb33c1c2cec73028fd..5cb12387311926e1856a60c3fdeb4b6d94289d49 100644 (file)
@@ -18,12 +18,12 @@ galaxy_info:
   # platform on this list, let us know and we'll get it added!
   #
   platforms:
-  #- name: EL
-  #  versions:
+  - name: EL
+    versions:
   #  - all
   #  - 5
   #  - 6
-  #  - 7
+    - 7
   #- name: GenericUNIX
   #  versions:
   #  - all
diff --git a/playbook.yml b/playbook.yml
new file mode 100644 (file)
index 0000000..a9a7bba
--- /dev/null
@@ -0,0 +1,25 @@
+---
+- 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:
+    - config_rabbitmq_ha: true
+    - enable_rabbitmq_clustering: true
+    - pri_domain_name: 'test.vagrant.local'
+    - rabbitmq_master: 'node0'
+  roles:
+    - role: ansible-rabbitmq
+  tasks:
diff --git a/requirements.yml b/requirements.yml
new file mode 100644 (file)
index 0000000..a1f51cb
--- /dev/null
@@ -0,0 +1,2 @@
+---
+- src: https://github.com/mrlesmithjr/ansible-rabbitmq.git
index bde00da90564a6b647e2e406aa67dd8a4f6e1029..1768dd90b7f59cc2c1d668cd9ca8565d90254bc8 100644 (file)
@@ -2,6 +2,9 @@
 - include: debian.yml
   when: ansible_os_family == "Debian"
 
+- include: redhat.yml
+  when: ansible_os_family == "RedHat"
+  
 - name: checking to see if already clustered
   stat: path=/etc/rabbitmq/clustered
   register: clustered
diff --git a/tasks/redhat.yml b/tasks/redhat.yml
new file mode 100644 (file)
index 0000000..bf6f1e1
--- /dev/null
@@ -0,0 +1,43 @@
+---
+- name: redhat | installing pre-reqs
+  yum:
+    name: "{{ item }}"
+    state: present
+  with_items:
+    - dnf
+    - epel-release
+    - python-dnf
+  when: >
+        ansible_distribution != "Fedora"
+
+- name: redhat | installing erlang
+  dnf:
+    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
+  dnf:
+    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