]> git.immae.eu Git - github/fretlink/ansible-rabbitmq.git/commitdiff
Cleaned up code as part of issue #10 enhancements/issues-9-10-11
authorLarry Smith Jr <mrlesmithjr@gmail.com>
Sun, 21 May 2017 01:19:34 +0000 (21:19 -0400)
committerLarry Smith Jr <mrlesmithjr@gmail.com>
Sun, 21 May 2017 01:19:34 +0000 (21:19 -0400)
Signed-off-by: Larry Smith Jr <mrlesmithjr@gmail.com>
README.md
defaults/main.yml
handlers/main.yml
tasks/debian.yml
tasks/fedora.yml
tasks/main.yml
tasks/rabbitmq_ha_config.yml
tasks/rabbitmq_users.yml
tasks/redhat.yml

index 99c019d9d8f74b14511bffd78e70e20a9006307b..b3b03adcea64556071421c27b9ee12a3ed1cbda6 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
 Role Name
 =========
 
-Installs rabbitmq https://www.rabbitmq.com/ (Configurable...HA and Clustering ready)
+An [Ansible] role to install/configure [RabbitMQ]
 
 Build Status
 ------------
@@ -11,67 +11,30 @@ 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
 ------------
@@ -81,33 +44,7 @@ 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:
-````
+[Example Playbook](./playbook.yml)
 
 License
 -------
@@ -118,6 +55,11 @@ Author Information
 ------------------
 
 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/>
index ad22eadf695334d91d7d7afdf5ad46ce7e6b600b..90d7fb599a842fd40b51a341d19513112e56ab6b 100644 (file)
@@ -1,28 +1,49 @@
 ---
 # 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'
index 259ce1c2dfa0b544af150d6965f5585c73da519a..4fdafe55f94dbe62abe93d8aebd09c8ba8850d7c 100644 (file)
@@ -4,3 +4,4 @@
   service:
     name: "rabbitmq-server"
     state: restarted
+  become: true
index a031ead18b4dae014bb1689993605106ee905056..b25d39b09cc393933332b32fc010768a40921b8f 100644 (file)
@@ -3,22 +3,26 @@
   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
 
@@ -26,6 +30,7 @@
   rabbitmq_plugin:
     names: rabbitmq_management
     state: enabled
+  become: true
   notify: restart rabbitmq-server
 
 - name: debian | ensuring that the RabbitMQ service is running
@@ -33,3 +38,4 @@
     name: rabbitmq-server
     state: started
     enabled: yes
+  become: true
index 3d929631ed745e3e5aae5a09e15b414793a60469..6ac9c03fc09d121e5220234577d15ee847c705ac 100644 (file)
@@ -3,6 +3,7 @@
   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
index bd82f932cd54b9f38dceb967c95166f3bded59d4..1da06c4420dafec6133338f4233dd566b0745530 100644 (file)
@@ -3,19 +3,30 @@
   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
index 8811b6dc9f017dd1d1c78d2e5fc3869533868a4c..bf74957c06f5f8dea618b33aa000b48e63f299fd 100644 (file)
@@ -6,39 +6,46 @@
 
 - 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
index 8bce8b27a0c1134bff1ccb2faaa3fb47e8f5de0d..98e45e2e35e0adbf4e91b748861a538a04e8ca5a 100644 (file)
@@ -1,27 +1,34 @@
 ---
 - 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
index 484597d923b39ce994b7bf241a06431b875d9ee3..afa714c66f560286c6aeb1acc51e46dbd7259486 100644 (file)
@@ -3,6 +3,7 @@
   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