From 3a14992832b16a71b7452cb0ecce10d44de52b0c Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Tue, 30 Aug 2022 07:50:44 -0500 Subject: [PATCH] add rabbitmq role --- roles/rabbitmq/defaults/main.yaml | 28 +++++++++++++++++ roles/rabbitmq/handlers/main.yaml | 12 +++++++ roles/rabbitmq/tasks/RedHat.yaml | 26 ++++++++++++++++ roles/rabbitmq/tasks/configure.yaml | 28 +++++++++++++++++ roles/rabbitmq/tasks/main.yaml | 38 +++++++++++++++++++++++ roles/rabbitmq/templates/rabbitmq.conf.j2 | 16 ++++++++++ roles/rabbitmq/vars/default.yaml | 0 7 files changed, 148 insertions(+) create mode 100644 roles/rabbitmq/defaults/main.yaml create mode 100644 roles/rabbitmq/handlers/main.yaml create mode 100644 roles/rabbitmq/tasks/RedHat.yaml create mode 100644 roles/rabbitmq/tasks/configure.yaml create mode 100644 roles/rabbitmq/tasks/main.yaml create mode 100644 roles/rabbitmq/templates/rabbitmq.conf.j2 create mode 100644 roles/rabbitmq/vars/default.yaml diff --git a/roles/rabbitmq/defaults/main.yaml b/roles/rabbitmq/defaults/main.yaml new file mode 100644 index 0000000..c2dd9cc --- /dev/null +++ b/roles/rabbitmq/defaults/main.yaml @@ -0,0 +1,28 @@ +--- +rabbitmq_package_name: rabbitmq-server +rabbitmq_package_state: present + +rabbitmq_service_name: rabbitmq-server +rabbitmq_service_state: started +rabbitmq_service_enabled: true + +rabbitmq_plugins_enabled: + - rabbitmq_management + - rabbitmq_prometheus + +rabbitmq_etc_path: /etc/rabbitmq +rabbitmq_var_path: /var/lib/rabbitmq +rabbitmq_config_path: "{{ rabbitmq_etc_path }}/rabbitmq.conf" + +rabbitmq_erlang_cookie_path: "{{ rabbitmq_var_path }}/.erlang.cookie" +rabbitmq_erlang_cookie_onwer: rabbitmq +rabbitmq_erlang_cookie_group: rabbitmq +rabbitmq_erlang_cookie_mode: "0400" +rabbitmq_erlang_cookie: "" + +rabbitmq_loopback_users: + +# rabbitmq_cluster_formation_peer_discovery_backend: classic_config +# rabbitmq_cluster_formation_classic_config_nodes: [] + +rabbitmq_vm_memory_high_watermark_relative: diff --git a/roles/rabbitmq/handlers/main.yaml b/roles/rabbitmq/handlers/main.yaml new file mode 100644 index 0000000..07635b2 --- /dev/null +++ b/roles/rabbitmq/handlers/main.yaml @@ -0,0 +1,12 @@ +--- +- name: reload rabbitmq + service: + name: "{{ rabbitmq_service_name }}" + state: reloaded + when: rabbitmq_service_enabled + +- name: restart rabbitmq + service: + name: "{{ rabbitmq_service_name }}" + state: restarted + when: rabbitmq_service_enabled diff --git a/roles/rabbitmq/tasks/RedHat.yaml b/roles/rabbitmq/tasks/RedHat.yaml new file mode 100644 index 0000000..a86a0de --- /dev/null +++ b/roles/rabbitmq/tasks/RedHat.yaml @@ -0,0 +1,26 @@ +--- +- name: add erlang yum repo + yum_repository: + name: rabbitmq_erlang + baseurl: https://packagecloud.io/rabbitmq/erlang/el/$releasever/$basearch + repo_gpgcheck: yes + gpgcheck: no + enabled: yes + gpgkey: https://packagecloud.io/rabbitmq/erlang/gpgkey + sslverify: yes + sslcacert: /etc/pki/tls/certs/ca-bundle.crt + metadata_expire: "300" + description: RabbitMQ Erlang Yum repo + +- name: add rabbitmq yum repo + yum_repository: + name: rabbitmq_rabbitmq-server + baseurl: https://packagecloud.io/rabbitmq/rabbitmq-server/el/$releasever/$basearch + repo_gpgcheck: true + gpgcheck: false + enabled: true + gpgkey: https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey + sslverify: true + sslcacert: /etc/pki/tls/certs/ca-bundle.crt + metadata_expire: "300" + description: RabbitMQ Yum repo diff --git a/roles/rabbitmq/tasks/configure.yaml b/roles/rabbitmq/tasks/configure.yaml new file mode 100644 index 0000000..6aa88b2 --- /dev/null +++ b/roles/rabbitmq/tasks/configure.yaml @@ -0,0 +1,28 @@ +--- +- name: configure erlang cookie + copy: + dest: "{{ rabbitmq_erlang_cookie_path }}" + owner: "{{ rabbitmq_erlang_cookie_onwer }}" + group: "{{ rabbitmq_erlang_cookie_group }}" + mode: "{{ rabbitmq_erlang_cookie_mode }}" + content: "{{ rabbitmq_erlang_cookie }}" + when: rabbitmq_erlang_cookie | length + notify: restart rabbitmq + +- name: configure + template: + src: rabbitmq.conf.j2 + dest: "{{ rabbitmq_config_path }}" + notify: restart rabbitmq + +- name: register enabled plugins + command: rabbitmq-plugins list --enabled --minimal + changed_when: false + register: rabbitmq_enabled_plugins + +- name: enable plugins + command: "rabbitmq-plugins enable {{ item }}" + loop: "{{ rabbitmq_plugins_enabled }}" + when: + - item not in rabbitmq_enabled_plugins.stdout_lines[1:] + diff --git a/roles/rabbitmq/tasks/main.yaml b/roles/rabbitmq/tasks/main.yaml new file mode 100644 index 0000000..9424a2d --- /dev/null +++ b/roles/rabbitmq/tasks/main.yaml @@ -0,0 +1,38 @@ +--- +- name: gather os specific variables + include_vars: "{{ lookup('first_found', possible_files) }}" + vars: + possible_files: + files: + - "{{ ansible_distribution }}-{{ ansible_distribution_version }}.yaml" + - "{{ ansible_distribution }}.yaml" + - "{{ ansible_os_family }}.yaml" + - "default.yaml" + paths: + - vars + +- name: include os specific tasks + include_tasks: "{{ lookup('first_found', possible_files) }}" + vars: + possible_files: + files: + - "{{ ansible_distribution }}-{{ ansible_distribution_version }}.yaml" + - "{{ ansible_distribution }}.yaml" + - "{{ ansible_os_family }}.yaml" + - "default.yaml" + paths: + - tasks + +- name: install + package: + name: "{{ rabbitmq_package_name }}" + state: "{{ rabbitmq_package_state }}" + +- name: configure + include: configure.yaml + +- name: manage service + service: + name: "{{ rabbitmq_service_name }}" + state: "{{ rabbitmq_service_state }}" + enabled: "{{ rabbitmq_service_enabled }}" diff --git a/roles/rabbitmq/templates/rabbitmq.conf.j2 b/roles/rabbitmq/templates/rabbitmq.conf.j2 new file mode 100644 index 0000000..603434b --- /dev/null +++ b/roles/rabbitmq/templates/rabbitmq.conf.j2 @@ -0,0 +1,16 @@ +# {{ ansible_managed }} + +{% if rabbitmq_loopback_users %} +loopback_users = {{ rabbitmq_loopback_users }} +{% endif %} +{% if rabbitmq_vm_memory_high_watermark_relative %} +vm_memory_high_watermark.relative = {{ rabbitmq_vm_memory_high_watermark_relative }} +{% endif %} +{% if rabbitmq_cluster_formation_peer_discovery_backend %} +cluster_formation.peer_discovery_backend = {{ rabbitmq_cluster_formation_peer_discovery_backend }} +{% endif %} +{% if rabbitmq_cluster_formation_classic_config_nodes %} +{% for node in rabbitmq_cluster_formation_classic_config_nodes %} +cluster_formation.classic_config.nodes.{{ loop.index }} = {{ node }} +{% endfor %} +{% endif %} diff --git a/roles/rabbitmq/vars/default.yaml b/roles/rabbitmq/vars/default.yaml new file mode 100644 index 0000000..e69de29