initial commit

This commit is contained in:
ace
2023-02-08 01:38:33 +03:00
commit 32f6503bfb
18 changed files with 561 additions and 0 deletions

33
tasks/Debian/install.yaml Normal file
View File

@ -0,0 +1,33 @@
---
- name: Add gpg keys for rabbitmq
ansible.builtin.apt_key:
url: "{{ item.url }}"
keyring: "{{ item.keyring }}"
loop: "{{ rabbitmq_debian_apt_key }}"
- name: Enable https transport for apt
apt:
name: apt-transport-https
update_cache: yes
- name: Add rabbitmq.list to sources
template:
src: "rabbitmq.list.j2"
dest: /etc/apt/sources.list.d/rabbitmq.list
- name: Install deps packages
apt:
name:
- socat
- logrotate
update_cache: yes
- name: Install erlang {{ erlang_debian_version }}
apt:
name: "{{ erlang_debian_package }}"
update_cache: yes
- name: Install rabbitmq {{ rabbitmq_debian_version }}
apt:
name: "{{ rabbitmq_debian_package}}={{ rabbitmq_debian_version }}"
update_cache: yes

19
tasks/RedHat/install.yaml Normal file
View File

@ -0,0 +1,19 @@
---
- name: Add rabbitmq.repo to yum.repos.d
template:
src: "rabbitmq.repo.j2"
dest: /etc/yum.repos.d/rabbitmq.repo
- name: Install deps packages
yum:
name:
- socat
- logrotate
- name: Install erlang {{ erlang_rhel_version }}
yum:
name: "{{ erlang_rhel_package }}-{{ erlang_rhel_version }}"
- name: Install rabbitmq {{ rabbitmq_rhel_version }}
yum:
name: "{{ rabbitmq_rhel_package }}-{{ rabbitmq_rhel_version }}"

View File

@ -0,0 +1,14 @@
---
- name: Add rabbitmq cluster hosts
lineinfile:
dest: /etc/hosts
line: "{{ hostvars[item].rabbitmq_cluster_ip_address | default(hostvars[item].ansible_default_ipv4.address) }} {{ hostvars[item].ansible_hostname }}"
with_items: "{{ ansible_play_hosts }}"
- name: Set erlang cookie
template:
src: erlang.cookie.j2
dest: "{{ rabbitmq_erlang_cookie_file }}"
owner: rabbitmq
group: rabbitmq
mode: 0400

8
tasks/configure.yaml Normal file
View File

@ -0,0 +1,8 @@
---
- name: Configure rabbitmq
template:
src: rabbitmq.conf.j2
dest: /etc/rabbitmq/rabbitmq.conf
notify:
- Restart RabbitMQ server
when: rabbitmq_conf is defined or rabbitmq_cluster

13
tasks/ha_policy.yaml Normal file
View File

@ -0,0 +1,13 @@
---
- name: Set policies
rabbitmq_policy:
apply_to: "{{ item.apply_to | default(omit) }}"
name: "{{ item.name | default('default_policy') }}"
pattern: "{{ item.pattern | default(omit) }}"
priority: "{{ item.priority | default(omit) }}"
state: "{{ item.state | default(omit) }}"
node: "{{ item.node | default(omit) }}"
vhost: "{{ item.vhost | default(omit) }}"
args:
tags: "{{ item.tags | default(omit) }}"
loop: "{{ rabbitmq_policies }}"

4
tasks/main.yaml Normal file
View File

@ -0,0 +1,4 @@
---
- include: rabbitmq.yaml
tags:
- rabbitmq

21
tasks/plugins.yaml Normal file
View File

@ -0,0 +1,21 @@
---
- name: Install rabbitmq plugins
get_url:
url: "{{ item.url }}"
dest: "{{ rabbitmq_plugin_dir }}"
with_items: "{{ rabbitmq_plugins }}"
when: item.url is defined
- name: Disable rabbitmq plugins
rabbitmq_plugin:
names: "{{ rabbitmq_plugins_disabled | join(',') }}"
state: disabled
- name: Set enabled rabbitmq plugins
set_fact:
rabbitmq_plugins_enabled: "{{ rabbitmq_plugins_enabled + [ item.name | default(item) ] }}"
with_items: "{{ rabbitmq_plugins }}"
- name: Enable rabbitmq plugins
rabbitmq_plugin:
names: "{{ rabbitmq_plugins_enabled | join(',') }}"

31
tasks/rabbitmq.yaml Normal file
View File

@ -0,0 +1,31 @@
---
- name: Include rabbitmq installation tasks
include: "{{ ansible_os_family }}/install.yaml"
- include: configure.yaml
- include: configure-cluster.yaml
when: rabbitmq_cluster
- name: Start rabbitmq server
service:
name: rabbitmq-server
enabled: True
state: started
- block:
- include: vhosts.yaml
- include: ha_policy.yaml
- include: users.yaml
when:
- rabbitmq_cluster
- ansible_hostname == hostvars[ansible_play_hosts.0].ansible_hostname
- block:
- include: vhosts.yaml
- include: ha_policy.yaml
- include: users.yaml
when:
- not rabbitmq_cluster
- include: plugins.yaml

18
tasks/users.yaml Normal file
View File

@ -0,0 +1,18 @@
---
- name: Remove rabbitmq users
rabbitmq_user:
user: "{{ item }}"
state: absent
with_items: "{{ rabbitmq_users_absent }}"
- name: Add rabbitmq users
rabbitmq_user:
user: "{{ item.user }}"
password: "{{ item.password }}"
vhost: "{{ item.vhost | default('/') }}"
configure_priv: "{{ item.configure_priv | default('.*') }}"
read_priv: "{{ item.read_priv | default('.*') }}"
write_priv: "{{ item.write_priv | default('.*') }}"
tags: "{{ item.tags | default('') }}"
no_log: true
with_items: "{{ rabbitmq_users }}"

14
tasks/vhosts.yaml Normal file
View File

@ -0,0 +1,14 @@
---
- name: Remove rabbitmq virtual hosts
rabbitmq_vhost:
name: "{{ item }}"
state: absent
with_items: "{{ rabbitmq_vhosts_absent }}"
- name: Add rabbitmq virtual hosts
rabbitmq_vhost:
name: "{{ item.name | default(item) }}"
node: "{{ item.node | default('rabbit') }}"
state: present
tracing: "{{ item.tracing | default(False) }}"
with_items: "{{ rabbitmq_vhosts }}"