Skip to content

Commit

Permalink
fix(cluster): add discovered inventory nodes to sysctl config
Browse files Browse the repository at this point in the history
  • Loading branch information
rockandska committed Nov 17, 2021
1 parent 972425f commit 7ee6752
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 25 deletions.
58 changes: 35 additions & 23 deletions tasks/config_server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,43 @@
or rabbitmq_slave_of != none
or rabbitmq_slave_of | d("") | length > 0

- name: "[RabbitMQ] Define cluster config for master"
- name: "[RabbitMQ] Define cluster nodes"
delegate_to: localhost
set_fact:
__rabbitmq_cluster_nodes: >-
'rabbit@{{ ansible_hostname }}',
'rabbit@{{ groups['all']
| map('extract',hostvars)
| selectattr('rabbitmq_slave_of','defined')
| selectattr('rabbitmq_slave_of', 'equalto', inventory_hostname)
| map(attribute='ansible_hostname') | join("','rabbit@")
}}'
__rabbitmq_cluster_nodes: |
{{
( __rabbitmq_cluster_nodes
| default([],True)
)
+ [
node if '@' in node else ([ node, hostvars[item]['ansible_hostname'] ] | join('@'))
]
}}
loop:
"{{
(
(
groups['all']
| map('extract',hostvars)
| selectattr('rabbitmq_slave_of','defined')
| selectattr('rabbitmq_slave_of','equalto',(rabbitmq_slave_of | d(inventory_hostname, true)))
| map(attribute='inventory_hostname')
| list
)
+
[ rabbitmq_slave_of | ternary(rabbitmq_slave_of,inventory_hostname) ]
) | unique
}}"
loop_control:
index_var: id
vars:
node: "{{ hostvars[item]['rabbitmq_node_name'] | d('rabbit',True) }}"
when:
- rabbitmq_is_master

- name: "[RabbitMQ] Define cluster config for slave"
set_fact:
__rabbitmq_cluster_nodes: >-
'rabbit@{{ hostvars[rabbitmq_slave_of].ansible_hostname }}',
'rabbit@{{ groups['all']
| map('extract',hostvars)
| selectattr('rabbitmq_slave_of','defined')
| selectattr('rabbitmq_slave_of', 'equalto', rabbitmq_slave_of)
| map(attribute='ansible_hostname') | join("','rabbit@")
}}'
when:
- rabbitmq_slave_of != none
- rabbitmq_slave_of | d("") | length > 0
or (
rabbitmq_slave_of != none
and rabbitmq_slave_of | d("") | length > 0
)

- name: "[RabbitMQ] Copy custom server config (sysctl format)"
template:
Expand All @@ -76,6 +87,7 @@
when:
- rabbitmq_sysctl_config | length == 0
- rabbitmq_series is version('3.7', '>=')
- __rabbitmq_cluster_nodes | d("", True) | length == 0

- name: "[RabbitMQ] Copy custom server config (erlang format)"
template:
Expand Down
4 changes: 3 additions & 1 deletion templates/etc/rabbitmq/erlang.config.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
{{ line }}
{% endfor %}
{% endif %}
{% if rabbitmq_series is version('3.7', '<') %}
{% if __rabbitmq_cluster_nodes | d("") | length > 0 and rabbitmq_peer_discovery_classic %}
{% if rabbitmq_erlang_config != None and rabbitmq_erlang_config | d("") | length > 0 %}
,
{% endif %}
{rabbit, [
{cluster_nodes, {[{{ __rabbitmq_cluster_nodes }}], {{ rabbitmq_cluster_node_type }} }}
{cluster_nodes, { {{ __rabbitmq_cluster_nodes }}, {{ rabbitmq_cluster_node_type }} } }
]}
{% endif %}
{% endif %}
].
10 changes: 9 additions & 1 deletion templates/etc/rabbitmq/sysctl.conf.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
#jinja2: trim_blocks: "true", lstrip_blocks: "false"
#jinja2: trim_blocks: True, lstrip_blocks: True
{%- if rabbitmq_series is version('3.7', '>=') -%}
{%- if __rabbitmq_cluster_nodes | d("") | length > 0 and rabbitmq_peer_discovery_classic -%}
cluster_formation.peer_discovery_backend = classic_config
{% for node in __rabbitmq_cluster_nodes %}
cluster_formation.classic_config.nodes.{{ loop.index }} = {{ node }}
{% endfor %}
{%- endif -%}
{%- endif -%}
{%- macro treedot(dict,string) -%}
{%- for key, value in dict.items() -%}
{%- if value is mapping -%}
Expand Down

0 comments on commit 7ee6752

Please sign in to comment.