diff options
author | Larry Smith Jr <mrlesmithjr@gmail.com> | 2017-05-20 21:19:34 -0400 |
---|---|---|
committer | Larry Smith Jr <mrlesmithjr@gmail.com> | 2017-05-20 21:19:34 -0400 |
commit | a67dde50f26e0f76d91f0744e8e8341dac95dae2 (patch) | |
tree | 2971e931788eddf51b9ec71ac063bfb951215d0c /tasks | |
parent | f36f2edd9429200fbd18eeecfbba4b5fe891f26d (diff) | |
download | ansible-rabbitmq-a67dde50f26e0f76d91f0744e8e8341dac95dae2.tar.gz ansible-rabbitmq-a67dde50f26e0f76d91f0744e8e8341dac95dae2.tar.zst ansible-rabbitmq-a67dde50f26e0f76d91f0744e8e8341dac95dae2.zip |
Cleaned up code as part of issue #10enhancements/issues-9-10-11
Signed-off-by: Larry Smith Jr <mrlesmithjr@gmail.com>
Diffstat (limited to 'tasks')
-rw-r--r-- | tasks/debian.yml | 6 | ||||
-rw-r--r-- | tasks/fedora.yml | 7 | ||||
-rw-r--r-- | tasks/main.yml | 17 | ||||
-rw-r--r-- | tasks/rabbitmq_ha_config.yml | 27 | ||||
-rw-r--r-- | tasks/rabbitmq_users.yml | 39 | ||||
-rw-r--r-- | tasks/redhat.yml | 7 |
6 files changed, 74 insertions, 29 deletions
diff --git a/tasks/debian.yml b/tasks/debian.yml index a031ead..b25d39b 100644 --- a/tasks/debian.yml +++ b/tasks/debian.yml | |||
@@ -3,22 +3,26 @@ | |||
3 | apt_key: | 3 | apt_key: |
4 | url: "{{ rabbitmq_debian_repo_key }}" | 4 | url: "{{ rabbitmq_debian_repo_key }}" |
5 | state: present | 5 | state: present |
6 | become: true | ||
6 | 7 | ||
7 | - name: debian | adding RabbitMQ repo | 8 | - name: debian | adding RabbitMQ repo |
8 | apt_repository: | 9 | apt_repository: |
9 | repo: "{{ rabbitmq_debian_repo }}" | 10 | repo: "{{ rabbitmq_debian_repo }}" |
10 | state: present | 11 | state: present |
11 | register: "rabbitmq_repo_added" | 12 | register: "rabbitmq_repo_added" |
13 | become: true | ||
12 | 14 | ||
13 | - name: debian | updating apt cache | 15 | - name: debian | updating apt cache |
14 | apt: | 16 | apt: |
15 | update_cache: yes | 17 | update_cache: yes |
18 | become: true | ||
16 | when: rabbitmq_repo_added.changed | 19 | when: rabbitmq_repo_added.changed |
17 | 20 | ||
18 | - name: debian | installing RabbitMQ server | 21 | - name: debian | installing RabbitMQ server |
19 | apt: | 22 | apt: |
20 | name: "{{ item }}" | 23 | name: "{{ item }}" |
21 | state: present | 24 | state: present |
25 | become: true | ||
22 | with_items: | 26 | with_items: |
23 | - rabbitmq-server | 27 | - rabbitmq-server |
24 | 28 | ||
@@ -26,6 +30,7 @@ | |||
26 | rabbitmq_plugin: | 30 | rabbitmq_plugin: |
27 | names: rabbitmq_management | 31 | names: rabbitmq_management |
28 | state: enabled | 32 | state: enabled |
33 | become: true | ||
29 | notify: restart rabbitmq-server | 34 | notify: restart rabbitmq-server |
30 | 35 | ||
31 | - name: debian | ensuring that the RabbitMQ service is running | 36 | - name: debian | ensuring that the RabbitMQ service is running |
@@ -33,3 +38,4 @@ | |||
33 | name: rabbitmq-server | 38 | name: rabbitmq-server |
34 | state: started | 39 | state: started |
35 | enabled: yes | 40 | enabled: yes |
41 | become: true | ||
diff --git a/tasks/fedora.yml b/tasks/fedora.yml index 3d92963..6ac9c03 100644 --- a/tasks/fedora.yml +++ b/tasks/fedora.yml | |||
@@ -3,6 +3,7 @@ | |||
3 | dnf: | 3 | dnf: |
4 | name: "{{ item }}" | 4 | name: "{{ item }}" |
5 | state: present | 5 | state: present |
6 | become: true | ||
6 | with_items: | 7 | with_items: |
7 | - wget | 8 | - wget |
8 | 9 | ||
@@ -10,30 +11,36 @@ | |||
10 | dnf: | 11 | dnf: |
11 | name: "erlang" | 12 | name: "erlang" |
12 | state: present | 13 | state: present |
14 | become: true | ||
13 | 15 | ||
14 | - name: fedora | adding RabbitMQ public GPG key | 16 | - name: fedora | adding RabbitMQ public GPG key |
15 | rpm_key: | 17 | rpm_key: |
16 | key: "{{ rabbitmq_redhat_repo_key }}" | 18 | key: "{{ rabbitmq_redhat_repo_key }}" |
17 | state: present | 19 | state: present |
20 | become: true | ||
18 | 21 | ||
19 | - name: fedora | downloading RabbitMQ | 22 | - name: fedora | downloading RabbitMQ |
20 | get_url: | 23 | get_url: |
21 | url: "{{ rabbitmq_redhat_url }}/{{ rabbitmq_redhat_package }}" | 24 | url: "{{ rabbitmq_redhat_url }}/{{ rabbitmq_redhat_package }}" |
22 | dest: "/opt/{{ rabbitmq_redhat_package }}" | 25 | dest: "/opt/{{ rabbitmq_redhat_package }}" |
26 | become: true | ||
23 | 27 | ||
24 | - name: fedora | installing RabbitMQ | 28 | - name: fedora | installing RabbitMQ |
25 | dnf: | 29 | dnf: |
26 | name: "/opt/{{ rabbitmq_redhat_package }}" | 30 | name: "/opt/{{ rabbitmq_redhat_package }}" |
27 | state: present | 31 | state: present |
32 | become: true | ||
28 | 33 | ||
29 | - name: fedora | starting and enabling RabbitMQ service | 34 | - name: fedora | starting and enabling RabbitMQ service |
30 | service: | 35 | service: |
31 | name: "rabbitmq-server" | 36 | name: "rabbitmq-server" |
32 | state: started | 37 | state: started |
33 | enabled: yes | 38 | enabled: yes |
39 | become: true | ||
34 | 40 | ||
35 | - name: fedora | enabling the RabbitMQ Management Console | 41 | - name: fedora | enabling the RabbitMQ Management Console |
36 | rabbitmq_plugin: | 42 | rabbitmq_plugin: |
37 | names: rabbitmq_management | 43 | names: rabbitmq_management |
38 | state: enabled | 44 | state: enabled |
39 | notify: restart rabbitmq-server | 45 | notify: restart rabbitmq-server |
46 | become: true | ||
diff --git a/tasks/main.yml b/tasks/main.yml index bd82f93..1da06c4 100644 --- a/tasks/main.yml +++ b/tasks/main.yml | |||
@@ -3,19 +3,30 @@ | |||
3 | when: ansible_os_family == "Debian" | 3 | when: ansible_os_family == "Debian" |
4 | 4 | ||
5 | - include: redhat.yml | 5 | - include: redhat.yml |
6 | when: ansible_distribution == "CentOS" or ansible_distribution == "Red Hat Enterprise Linux" | 6 | when: > |
7 | ansible_distribution == "CentOS" or | ||
8 | ansible_distribution == "Red Hat Enterprise Linux" | ||
7 | 9 | ||
8 | - include: fedora.yml | 10 | - include: fedora.yml |
9 | when: ansible_distribution == "Fedora" | 11 | when: ansible_distribution == "Fedora" |
10 | 12 | ||
13 | - include: config.yml | ||
14 | when: rabbitmq_config_service | ||
15 | |||
11 | - name: checking to see if already clustered | 16 | - name: checking to see if already clustered |
12 | stat: path=/etc/rabbitmq/clustered | 17 | stat: path=/etc/rabbitmq/clustered |
13 | register: clustered | 18 | register: clustered |
14 | 19 | ||
15 | - include: rabbitmq_clustering.yml | 20 | - include: rabbitmq_clustering.yml |
16 | when: rabbitmq_enable_clustering and (clustered.stat.exists != True) | 21 | when: > |
22 | rabbitmq_enable_clustering and | ||
23 | not clustered['stat']['exists'] | ||
17 | 24 | ||
18 | - include: rabbitmq_ha_config.yml | 25 | - include: rabbitmq_ha_config.yml |
19 | when: rabbitmq_config_ha and rabbitmq_enable_clustering | 26 | when: > |
27 | rabbitmq_config_ha and | ||
28 | rabbitmq_enable_clustering and | ||
29 | rabbitmq_config is defined | ||
20 | 30 | ||
21 | - include: rabbitmq_users.yml | 31 | - include: rabbitmq_users.yml |
32 | when: rabbitmq_users is defined | ||
diff --git a/tasks/rabbitmq_ha_config.yml b/tasks/rabbitmq_ha_config.yml index 8811b6d..bf74957 100644 --- a/tasks/rabbitmq_ha_config.yml +++ b/tasks/rabbitmq_ha_config.yml | |||
@@ -6,39 +6,46 @@ | |||
6 | 6 | ||
7 | - name: rabbitmq_ha_config | install rabbitMQ admin | 7 | - name: rabbitmq_ha_config | install rabbitMQ admin |
8 | shell: wget http://guest:guest@localhost:15672/cli/rabbitmqadmin | 8 | shell: wget http://guest:guest@localhost:15672/cli/rabbitmqadmin |
9 | when: not rabbitmqadmin_check.stat.exists | 9 | become: true |
10 | when: not rabbitmqadmin_check['stat']['exists'] | ||
10 | 11 | ||
11 | - name: rabbitmq_ha_config | moving the rabbitMQ Admin | 12 | - name: rabbitmq_ha_config | moving the rabbitMQ Admin |
12 | shell: mv rabbitmqadmin /usr/sbin | 13 | shell: mv rabbitmqadmin /usr/sbin |
13 | when: not rabbitmqadmin_check.stat.exists | 14 | become: true |
15 | when: not rabbitmqadmin_check['stat']['exists'] | ||
14 | 16 | ||
15 | - name: rabbitmq_ha_config | making executable rabbitMQ Admin | 17 | - name: rabbitmq_ha_config | making executable rabbitMQ Admin |
16 | shell: chmod +x /usr/sbin/rabbitmqadmin | 18 | shell: chmod +x /usr/sbin/rabbitmqadmin |
17 | notify: restart rabbitmq-server | 19 | notify: restart rabbitmq-server |
18 | when: not rabbitmqadmin_check.stat.exists | 20 | become: true |
21 | when: not rabbitmqadmin_check['stat']['exists'] | ||
19 | 22 | ||
20 | - name: rabbitmq_ha_config | creating queue(s) | 23 | - name: rabbitmq_ha_config | creating queue(s) |
21 | command: rabbitmqadmin declare queue name={{ item.queue_name }} durable={{ item.durable|lower }} | 24 | command: rabbitmqadmin declare queue name={{ item['queue_name'] }} durable={{ item['durable']|lower }} |
22 | run_once: true | 25 | run_once: true |
26 | become: true | ||
23 | with_items: "{{ rabbitmq_config }}" | 27 | with_items: "{{ rabbitmq_config }}" |
24 | 28 | ||
25 | - name: rabbitmq_ha_config | setting up ha on queue(s) | 29 | - name: rabbitmq_ha_config | setting up ha on queue(s) |
26 | rabbitmq_policy: | 30 | rabbitmq_policy: |
27 | name: "ha-all" | 31 | name: "ha-all" |
28 | pattern: "{{ item.queue_name }}" | 32 | pattern: "{{ item['queue_name'] }}" |
29 | tags: "{{ item.tags }}" | 33 | tags: "{{ item['tags'] }}" |
30 | state: present | 34 | state: present |
31 | run_once: true | 35 | run_once: true |
36 | become: true | ||
32 | with_items: "{{ rabbitmq_config }}" | 37 | with_items: "{{ rabbitmq_config }}" |
33 | 38 | ||
34 | - name: rabbitmq_ha_config | creating exchange(s) | 39 | - name: rabbitmq_ha_config | creating exchange(s) |
35 | command: rabbitmqadmin declare exchange name={{ item.exchange_name }} type={{ item.type }} | 40 | command: rabbitmqadmin declare exchange name={{ item['exchange_name'] }} type={{ item['type'] }} |
36 | run_once: true | 41 | run_once: true |
42 | become: true | ||
37 | with_items: "{{ rabbitmq_config }}" | 43 | with_items: "{{ rabbitmq_config }}" |
38 | when: item.exchange_name is defined | 44 | when: item['exchange_name'] is defined |
39 | 45 | ||
40 | - name: rabbitmq_ha_config | creating binding(s) | 46 | - name: rabbitmq_ha_config | creating binding(s) |
41 | command: rabbitmqadmin declare binding source={{ item.exchange_name }} destination_type="queue" destination={{ item.queue_name }} routing_key={{ item.routing_key }} | 47 | command: rabbitmqadmin declare binding source={{ item['exchange_name'] }} destination_type="queue" destination={{ item['queue_name'] }} routing_key={{ item['routing_key'] }} |
42 | run_once: true | 48 | run_once: true |
49 | become: true | ||
43 | with_items: "{{ rabbitmq_config }}" | 50 | with_items: "{{ rabbitmq_config }}" |
44 | when: item.exchange_name is defined | 51 | when: item['exchange_name'] is defined |
diff --git a/tasks/rabbitmq_users.yml b/tasks/rabbitmq_users.yml index 8bce8b2..98e45e2 100644 --- a/tasks/rabbitmq_users.yml +++ b/tasks/rabbitmq_users.yml | |||
@@ -1,27 +1,34 @@ | |||
1 | --- | 1 | --- |
2 | - name: rabbitmq_users | creating rabbitmq users | 2 | - name: rabbitmq_users | creating rabbitmq users |
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'] }}" |
7 | configure_priv: "{{ item.configure_priv }}" | 7 | configure_priv: "{{ item['configure_priv'] }}" |
8 | read_priv: "{{ item.read_priv }}" | 8 | read_priv: "{{ item['read_priv'] }}" |
9 | write_priv: "{{ item.write_priv }}" | 9 | write_priv: "{{ item['write_priv'] }}" |
10 | tags: "{{ item.tags }}" | 10 | tags: "{{ item['tags'] }}" |
11 | state: present | 11 | state: present |
12 | become: true | ||
12 | with_items: "{{ rabbitmq_users }}" | 13 | with_items: "{{ rabbitmq_users }}" |
13 | when: (rabbitmq_enable_clustering is defined and not rabbitmq_enable_clustering) or rabbitmq_enable_clustering is not defined | 14 | when: > |
15 | (rabbitmq_enable_clustering is defined and | ||
16 | not rabbitmq_enable_clustering) or | ||
17 | rabbitmq_enable_clustering is not defined | ||
14 | 18 | ||
15 | - name: rabbitmq_users | creating rabbitmq users | 19 | - name: rabbitmq_users | creating rabbitmq users |
16 | rabbitmq_user: | 20 | rabbitmq_user: |
17 | name: "{{ item.name }}" | 21 | name: "{{ item['name'] }}" |
18 | password: "{{ item.password }}" | 22 | password: "{{ item['password'] }}" |
19 | vhost: "{{ item.vhost }}" | 23 | vhost: "{{ item['vhost'] }}" |
20 | configure_priv: "{{ item.configure_priv }}" | 24 | configure_priv: "{{ item['configure_priv'] }}" |
21 | read_priv: "{{ item.read_priv }}" | 25 | read_priv: "{{ item['read_priv'] }}" |
22 | write_priv: "{{ item.write_priv }}" | 26 | write_priv: "{{ item['write_priv'] }}" |
23 | tags: "{{ item.tags }}" | 27 | tags: "{{ item['tags'] }}" |
24 | state: present | 28 | state: present |
25 | run_once: yes | 29 | run_once: yes |
30 | become: true | ||
26 | with_items: "{{ rabbitmq_users }}" | 31 | with_items: "{{ rabbitmq_users }}" |
27 | when: (rabbitmq_enable_clustering is defined and rabbitmq_enable_clustering) | 32 | when: > |
33 | rabbitmq_enable_clustering is defined and | ||
34 | rabbitmq_enable_clustering | ||
diff --git a/tasks/redhat.yml b/tasks/redhat.yml index 484597d..afa714c 100644 --- a/tasks/redhat.yml +++ b/tasks/redhat.yml | |||
@@ -3,6 +3,7 @@ | |||
3 | yum: | 3 | yum: |
4 | name: "{{ item }}" | 4 | name: "{{ item }}" |
5 | state: present | 5 | state: present |
6 | become: true | ||
6 | with_items: | 7 | with_items: |
7 | - epel-release | 8 | - epel-release |
8 | - wget | 9 | - wget |
@@ -11,30 +12,36 @@ | |||
11 | yum: | 12 | yum: |
12 | name: "erlang" | 13 | name: "erlang" |
13 | state: present | 14 | state: present |
15 | become: true | ||
14 | 16 | ||
15 | - name: redhat | adding RabbitMQ public GPG key | 17 | - name: redhat | adding RabbitMQ public GPG key |
16 | rpm_key: | 18 | rpm_key: |
17 | key: "{{ rabbitmq_redhat_repo_key }}" | 19 | key: "{{ rabbitmq_redhat_repo_key }}" |
18 | state: present | 20 | state: present |
21 | become: true | ||
19 | 22 | ||
20 | - name: redhat | downloading RabbitMQ | 23 | - name: redhat | downloading RabbitMQ |
21 | get_url: | 24 | get_url: |
22 | url: "{{ rabbitmq_redhat_url }}/{{ rabbitmq_redhat_package }}" | 25 | url: "{{ rabbitmq_redhat_url }}/{{ rabbitmq_redhat_package }}" |
23 | dest: "/opt/{{ rabbitmq_redhat_package }}" | 26 | dest: "/opt/{{ rabbitmq_redhat_package }}" |
27 | become: true | ||
24 | 28 | ||
25 | - name: redhat | installing RabbitMQ | 29 | - name: redhat | installing RabbitMQ |
26 | yum: | 30 | yum: |
27 | name: "/opt/{{ rabbitmq_redhat_package }}" | 31 | name: "/opt/{{ rabbitmq_redhat_package }}" |
28 | state: present | 32 | state: present |
33 | become: true | ||
29 | 34 | ||
30 | - name: redhat | starting and enabling RabbitMQ service | 35 | - name: redhat | starting and enabling RabbitMQ service |
31 | service: | 36 | service: |
32 | name: "rabbitmq-server" | 37 | name: "rabbitmq-server" |
33 | state: started | 38 | state: started |
34 | enabled: yes | 39 | enabled: yes |
40 | become: true | ||
35 | 41 | ||
36 | - name: redhat | enabling the RabbitMQ Management Console | 42 | - name: redhat | enabling the RabbitMQ Management Console |
37 | rabbitmq_plugin: | 43 | rabbitmq_plugin: |
38 | names: rabbitmq_management | 44 | names: rabbitmq_management |
39 | state: enabled | 45 | state: enabled |
40 | notify: restart rabbitmq-server | 46 | notify: restart rabbitmq-server |
47 | become: true | ||