aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--defaults/main.yml10
-rw-r--r--tasks/main.yml3
-rw-r--r--tasks/rabbitmq_ha_config.yml18
-rw-r--r--tasks/rabbitmq_users.yml23
-rw-r--r--tasks/rabbitmq_vhosts.yml25
5 files changed, 59 insertions, 20 deletions
diff --git a/defaults/main.yml b/defaults/main.yml
index 2932de7..f8dd8f9 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -31,6 +31,8 @@ rabbitmq_debian_version: 3.7.9
31 31
32# Defines if setting up a rabbitmq cluster 32# Defines if setting up a rabbitmq cluster
33rabbitmq_enable_clustering: false 33rabbitmq_enable_clustering: false
34# Defines the inventory host that should be considered master
35rabbitmq_master: None
34 36
35rabbitmq_erlang_cookie_file: /var/lib/rabbitmq/.erlang.cookie 37rabbitmq_erlang_cookie_file: /var/lib/rabbitmq/.erlang.cookie
36 38
@@ -52,14 +54,16 @@ rabitmq_ssl_options: {}
52# verify: verify_peer 54# verify: verify_peer
53# fail_if_no_peer_cert: "false" 55# fail_if_no_peer_cert: "false"
54 56
55# Defines the inventory host that should be considered master
56rabbitmq_master: []
57
58rabbitmq_redhat_repo_key: https://www.rabbitmq.com/rabbitmq-signing-key-public.asc 57rabbitmq_redhat_repo_key: https://www.rabbitmq.com/rabbitmq-signing-key-public.asc
59rabbitmq_redhat_package: "rabbitmq-server-{{ rabbitmq_redhat_version }}-1.noarch.rpm" 58rabbitmq_redhat_package: "rabbitmq-server-{{ rabbitmq_redhat_version }}-1.noarch.rpm"
60rabbitmq_redhat_url: "http://www.rabbitmq.com/releases/rabbitmq-server/v{{ rabbitmq_redhat_version }}" 59rabbitmq_redhat_url: "http://www.rabbitmq.com/releases/rabbitmq-server/v{{ rabbitmq_redhat_version }}"
61rabbitmq_redhat_version: 3.6.1 60rabbitmq_redhat_version: 3.6.1
62 61
62# Define extra vhosts to be created
63rabbitmq_extra_vhosts: []
64# - name: /
65# state: present
66
63# Define admin user to create in order to login to WebUI 67# Define admin user to create in order to login to WebUI
64rabbitmq_users: 68rabbitmq_users:
65 - name: rabbitmqadmin 69 - name: rabbitmqadmin
diff --git a/tasks/main.yml b/tasks/main.yml
index 1ef08f0..a9dc4d2 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -26,6 +26,9 @@
26 rabbitmq_enable_clustering and 26 rabbitmq_enable_clustering and
27 not clustered['stat']['exists'] 27 not clustered['stat']['exists']
28 28
29- include: rabbitmq_vhosts.yml
30 when: rabbitmq_extra_vhosts is defined
31
29- include: rabbitmq_ha_config.yml 32- include: rabbitmq_ha_config.yml
30 when: > 33 when: >
31 rabbitmq_config_ha and 34 rabbitmq_config_ha and
diff --git a/tasks/rabbitmq_ha_config.yml b/tasks/rabbitmq_ha_config.yml
index cea301c..322172d 100644
--- a/tasks/rabbitmq_ha_config.yml
+++ b/tasks/rabbitmq_ha_config.yml
@@ -13,9 +13,18 @@
13 notify: restart rabbitmq-server 13 notify: restart rabbitmq-server
14 when: not rabbitmqadmin_check['stat']['exists'] 14 when: not rabbitmqadmin_check['stat']['exists']
15 15
16- name: rabbitmq_ha_config | creating exchange(s)
17 command: rabbitmqadmin declare exchange name={{ item['exchange_name'] }} type={{ item['type'] }} --vhost={{ item['vhost'] | default('/') }}
18 run_once: true
19 delegate_to: "{{ rabbitmq_master }}"
20 become: true
21 with_items: "{{ rabbitmq_config }}"
22 when: item['exchange_name'] is defined
23
16- name: rabbitmq_ha_config | creating queue(s) 24- name: rabbitmq_ha_config | creating queue(s)
17 command: rabbitmqadmin declare queue name={{ item['queue_name'] }} durable={{ item['durable']|lower }} --vhost={{ item['vhost'] | default('/') }} 25 command: rabbitmqadmin declare queue name={{ item['queue_name'] }} durable={{ item['durable']|lower }} --vhost={{ item['vhost'] | default('/') }}
18 run_once: true 26 run_once: true
27 delegate_to: "{{ rabbitmq_master }}"
19 become: true 28 become: true
20 when: 29 when:
21 - item['queue_name'] is defined 30 - item['queue_name'] is defined
@@ -32,20 +41,15 @@
32 policy_vhost: "{{ item.vhost | default('/') }}" 41 policy_vhost: "{{ item.vhost | default('/') }}"
33 policy_name: "{{ item.policy_pattern is defined | ternary(policy_vhost + item.policy_pattern|default(''),item.queue_name|default('')) }}" 42 policy_name: "{{ item.policy_pattern is defined | ternary(policy_vhost + item.policy_pattern|default(''),item.queue_name|default('')) }}"
34 run_once: true 43 run_once: true
44 delegate_to: "{{ rabbitmq_master }}"
35 become: true 45 become: true
36 when: item.queue_name is defined or item.policy_pattern is defined 46 when: item.queue_name is defined or item.policy_pattern is defined
37 with_items: "{{ rabbitmq_config }}" 47 with_items: "{{ rabbitmq_config }}"
38 48
39- name: rabbitmq_ha_config | creating exchange(s)
40 command: rabbitmqadmin declare exchange name={{ item['exchange_name'] }} type={{ item['type'] }} --vhost={{ item['vhost'] | default('/') }}
41 run_once: true
42 become: true
43 with_items: "{{ rabbitmq_config }}"
44 when: item['exchange_name'] is defined
45
46- name: rabbitmq_ha_config | creating binding(s) 49- name: rabbitmq_ha_config | creating binding(s)
47 command: rabbitmqadmin declare binding source={{ item['exchange_name'] }} destination_type="queue" destination={{ item['queue_name'] }} routing_key={{ item['routing_key'] }} --vhost={{ item['vhost'] | default('/') }} 50 command: rabbitmqadmin declare binding source={{ item['exchange_name'] }} destination_type="queue" destination={{ item['queue_name'] }} routing_key={{ item['routing_key'] }} --vhost={{ item['vhost'] | default('/') }}
48 run_once: true 51 run_once: true
52 delegate_to: "{{ rabbitmq_master }}"
49 become: true 53 become: true
50 with_items: "{{ rabbitmq_config }}" 54 with_items: "{{ rabbitmq_config }}"
51 when: item['exchange_name'] is defined 55 when: item['exchange_name'] is defined
diff --git a/tasks/rabbitmq_users.yml b/tasks/rabbitmq_users.yml
index 98e45e2..7bba65e 100644
--- a/tasks/rabbitmq_users.yml
+++ b/tasks/rabbitmq_users.yml
@@ -3,11 +3,12 @@
3 rabbitmq_user: 3 rabbitmq_user:
4 name: "{{ item['name'] }}" 4 name: "{{ item['name'] }}"
5 password: "{{ item['password'] }}" 5 password: "{{ item['password'] }}"
6 vhost: "{{ item['vhost'] }}" 6 vhost: "{{ item['vhost']|default(omit) }}"
7 configure_priv: "{{ item['configure_priv'] }}" 7 configure_priv: "{{ item['configure_priv']|default(omit) }}"
8 read_priv: "{{ item['read_priv'] }}" 8 read_priv: "{{ item['read_priv']|default(omit) }}"
9 write_priv: "{{ item['write_priv'] }}" 9 write_priv: "{{ item['write_priv']|default(omit) }}"
10 tags: "{{ item['tags'] }}" 10 tags: "{{ item['tags']|default(omit) }}"
11 permissions: "{{ item['permissions']|default(omit) }}"
11 state: present 12 state: present
12 become: true 13 become: true
13 with_items: "{{ rabbitmq_users }}" 14 with_items: "{{ rabbitmq_users }}"
@@ -20,13 +21,15 @@
20 rabbitmq_user: 21 rabbitmq_user:
21 name: "{{ item['name'] }}" 22 name: "{{ item['name'] }}"
22 password: "{{ item['password'] }}" 23 password: "{{ item['password'] }}"
23 vhost: "{{ item['vhost'] }}" 24 vhost: "{{ item['vhost']|default(omit) }}"
24 configure_priv: "{{ item['configure_priv'] }}" 25 configure_priv: "{{ item['configure_priv']|default(omit) }}"
25 read_priv: "{{ item['read_priv'] }}" 26 read_priv: "{{ item['read_priv']|default(omit) }}"
26 write_priv: "{{ item['write_priv'] }}" 27 write_priv: "{{ item['write_priv']|default(omit) }}"
27 tags: "{{ item['tags'] }}" 28 tags: "{{ item['tags']|default(omit) }}"
29 permissions: "{{ item['permissions']|default(omit) }}"
28 state: present 30 state: present
29 run_once: yes 31 run_once: yes
32 delegate_to: "{{ rabbitmq_master }}"
30 become: true 33 become: true
31 with_items: "{{ rabbitmq_users }}" 34 with_items: "{{ rabbitmq_users }}"
32 when: > 35 when: >
diff --git a/tasks/rabbitmq_vhosts.yml b/tasks/rabbitmq_vhosts.yml
new file mode 100644
index 0000000..a02af62
--- /dev/null
+++ b/tasks/rabbitmq_vhosts.yml
@@ -0,0 +1,25 @@
1---
2- name: rabbitmq_extra_vhosts | Create vhosts
3 rabbitmq_vhost:
4 name: "{{ item['name'] }}"
5 state: "{{ item['state'] }}"
6 with_items: "{{ rabbitmq_extra_vhosts }}"
7 run_once: "{{ rabbitmq_enable_clustering is defined and rabbitmq_enable_clustering }}"
8 register: rabbitmq_created_vhosts
9
10- name: rabbitmq_extra_vhosts | Check guest administrator is present
11 command: rabbitmqctl -q list_users
12 become: true
13 run_once: "{{ rabbitmq_enable_clustering is defined and rabbitmq_enable_clustering }}"
14 when: rabbitmq_created_vhosts.changed
15 changed_when: false
16 register: rabbitmq_existing_users
17
18- name: rabbitmq_extra_vhosts | Give access to new vhosts to guest administrator
19 command: "rabbitmqctl -q set_permissions -p {{ item['name'] }} guest '.*' '.*' '.*'"
20 become: true
21 run_once: "{{ rabbitmq_enable_clustering is defined and rabbitmq_enable_clustering }}"
22 with_items: "{{ rabbitmq_created_vhosts.results|selectattr('changed')|list }}"
23 when:
24 - item['state'] == 'present'
25 - rabbitmq_existing_users.stdout_lines | map('regex_search', '^guest\\s\\[.*administrator.*\\]$') | list | difference([None]) | length > 0