Skip to content

Commit 75cbd35

Browse files
authored
Merge pull request #2 from hellofresh/fix/cluster_fixes
Fix/cluster fixes
2 parents bd6d8f2 + 2250ac2 commit 75cbd35

File tree

9 files changed

+151
-13
lines changed

9 files changed

+151
-13
lines changed

.kitchen.yml

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,65 @@ provisioner:
2424
use_instance_name : true
2525
groups :
2626
rabbitmq-cluster :
27-
- "cluster-1-docker-u14"
28-
- "cluster-2-docker-u14"
29-
- "cluster-3-docker-u14"
27+
- "cluster1.192.168.110.10.xip.io"
28+
- "cluster2.192.168.110.20.xip.io"
29+
# - "cluster-3-docker-u14"
3030
platforms:
3131
- name : docker-u14
3232
driver_config :
3333
image : quay.io/hellofresh/kitchen-base
3434
platform : ubuntu
3535
driver :
3636
name : docker
37+
socket : unix:///var/run/docker.sock
38+
use_sudo : false
3739

3840
suites :
3941
- name : standalone
4042
provisioner :
4143
playbook : "test/integration/standalone/standalone.yml"
4244
verifier :
4345
patterns : [ test/integration/standalone/serverspec/*_spec.rb ]
44-
driver_config :
45-
run_options : "-p 192.168.99.100:22:22"
4646

47-
- name : cluster_1
47+
- name : cluster1
4848
provisioner :
4949
playbook : "test/integration/cluster_1/cluster_1.yml"
50+
inventory_hostname: cluster1.192.168.110.10.xip.io
5051
verifier :
5152
patterns : [ test/integration/cluster_1/serverspec/*_spec.rb ]
5253
driver_config :
53-
run_options : --ip=172.17.0.11
54+
run_options : "--net cluster_network --ip=192.168.110.10"
55+
publish_all : true
56+
hostname : cluster1
57+
instance_name : cluster1
58+
# links :
59+
# - "cluster_2:cluster_2"
60+
# - "cluster_3:cluster_3"
61+
62+
- name : cluster2.192.168.110.20.xip.io
63+
provisioner :
64+
playbook : "test/integration/cluster_2/cluster_2.yml"
65+
inventory_hostname: cluster2.192.168.120.10.xip.io
66+
verifier :
67+
patterns : [ test/integration/cluster_2/serverspec/*_spec.rb ]
68+
driver_config :
69+
run_options : "--net cluster_network --ip=192.168.110.20"
70+
publish_all : true
71+
hostname : cluster2
72+
instance_name : cluster2
73+
# links :
74+
# - "cluster_1:cluster_1"
75+
# - "cluster_3:cluster_3"
76+
77+
- name : cluster3
78+
provisioner :
79+
playbook : "test/integration/cluster_3/cluster_3.yml"
80+
verifier :
81+
patterns : [ test/integration/cluster_3/serverspec/*_spec.rb ]
82+
driver_config :
83+
instance_name : cluster3
84+
publish_all : true
85+
# links :
86+
# - "cluster_1:cluster_1"
87+
# - "cluster_2:cluster_2"
88+

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ source 'https://rubygems.org'
33
#gem 'net-ssh','~> 2.9'
44
# Could
55
gem 'kitchen-verifier-serverspec','~> 0.5.0'
6-
gem 'kitchen-ansiblepush'
6+
gem 'kitchen-ansiblepush', :git => 'https://github.com/ahelal/kitchen-ansiblepush', :ref => "feb8c904e600bab0361d1a287d3fa307a1da1bb1"
77
gem 'kitchen-docker'
88
gem 'serverspec'

defaults/main.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ rabbitmq_cluster_api_user : "api-automation"
6666
rabbitmq_cluster_api_password : "api-password"
6767

6868
# How to get the IPs of cluster
69-
rabbitmq_clustering_resolve_names : "ansible" # ['ansible', dns]
69+
rabbitmq_clustering_resolve_names : "dns" # ['no', dns]
7070

7171
## Probably dont need to change that stuff
7272
### Construct a regex to match group before .
7373
rabbitmq_cluster_post_fix_domain_regex_replace: "([^.]*).*"
7474
# Print extra message related to inventory
7575
rabbitmq_cluster_debug : false
76+
#
77+
rabbit_cluster_nodes_version : []
7678

tasks/cluster/checks.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
---
22

3-
- name: cluster | check cluster group
3+
- name: check | cluster group should be valid
44
fail:
55
msg="Your configuration is not valid 'rabbitmq_cluster_group' varaible with value '{{ rabbitmq_cluster_group }}' is not valid group."
66
when: "{{ groups[rabbitmq_cluster_group] is not defined }}"
7+
8+
- name: check | get rabbitmq version in each node in the cluster
9+
shell: rabbitmqctl status|grep "{rabbit,\"RabbitMQ\"" | cut -d, -f3 | cut -d "\"" -f2
10+
delegate_to: "{{ item }}"
11+
changed_when: false
12+
run_once: true
13+
with_items: "{{ groups[rabbitmq_cluster_group] }}"
14+
register: cluster_versions_command
15+
16+
- name: check | Create a list of nodes and versions
17+
set_fact:
18+
rabbit_cluster_nodes_version: "{{ [{ 'node': item.item, 'version': item.stdout }] + rabbit_cluster_nodes_version }}"
19+
with_items: "{{ cluster_versions_command.results }}"
20+
run_once: true
21+
22+
# Filter out node values that are not the same version then compae with original node version
23+
# if lists dont match then we have different versions in our cluster
24+
- name: check | Fail if version in cluster dont match
25+
fail:
26+
msg="Rabbiqmq version in cluster dont match. Node versions = {{rabbit_cluster_nodes_version }}"
27+
run_once: true
28+
when: "{{ rabbit_cluster_nodes_version | selectattr('version', 'equalto', rabbit_cluster_nodes_version[0]['version']) | list != rabbit_cluster_nodes_version }}"

tasks/cluster/hostnames.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
23
# RabbitMQ uses short names for hosts. We need to make them resolvable along all the clusters
34
- name: hostnames | resolve cluster IPs with DNS
45
debug:
@@ -12,7 +13,7 @@
1213
- name: hostnames | manage cluster nodes in host file
1314
lineinfile:
1415
dest="/etc/hosts"
15-
regexp="^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}\s+{{ item.1 | replace('.' + rabbitmq_cluster_post_fix_domain, '') }} {{ '#' }}ansible-rabbitmq-role"
16+
regexp="^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}\s{{ item.1.split('.')[0] }} {{ '#' }}ansible-rabbitmq-role"
1617
line="{{ rabbitmq_server_ips['results'][item.0]['msg'] }}{{'\t'}}{{ item.1.split('.')[0] }} {{ '#' }}ansible-rabbitmq-role"
1718
state="present"
18-
with_items: "{{ groups[rabbitmq_cluster_group] | difference([inventory_hostname]) }}"
19+
with_indexed_items: "{{ groups[rabbitmq_cluster_group] | difference([inventory_hostname]) }}"

tasks/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- block:
2020
- include: cluster/checks.yml
2121
- include: cluster/hostnames.yml
22+
when: rabbitmq_clustering_resolve_names != "no"
2223
- include: cluster/erlang_cookie.yml
2324
- include: cluster/cluster.yml
2425
when: rabbitmq_clustering

test.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/sh
2+
set -e
3+
4+
if [ "$1" == "run" ]; then
5+
echo ""
6+
echo "**** Running tests ****"
7+
echo "-> Docker creating userdefined network"
8+
docker network create --subnet 192.168.110.0/24 cluster_network
9+
10+
echo "-> Create cluster1"
11+
bundle exec kitchen create cluster1
12+
13+
echo "-> Create cluster2"
14+
bundle exec kitchen create cluster2
15+
16+
elif [ "$1" == "destroy" ]; then
17+
set +e
18+
echo ""
19+
echo "**** Running destroy ****"
20+
21+
echo "-> Destroy cluster1 "
22+
bundle exec kitchen destroy cluster1
23+
docker rm cluster1
24+
25+
echo "-> Destroy cluster2 "
26+
bundle exec kitchen destroy cluster2
27+
docker rm cluster2
28+
29+
echo "-> Docker remove userdefined network"
30+
docker network rm cluster_network
31+
else
32+
echo "unsupported option '$1'"
33+
echo "usage [ run | destroy ]"
34+
exit 1
35+
fi

test/integration/cluster_1/cluster_1.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- hosts: all
44
become: true
55
vars:
6+
rabbitmq_clustering_resolve_names : "no"
67
rabbitmq_ssl : false
78
#rabbitmq_plugins : ["rabbitmq_management","rabbitmq_tracing"]
89
rabbitmq_conf_tcp_listeners_address : "0.0.0.0"
Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,42 @@
1-
cluster_2.yml
1+
---
2+
3+
- hosts: all
4+
become: true
5+
vars:
6+
rabbitmq_ssl : false
7+
#rabbitmq_plugins : ["rabbitmq_management","rabbitmq_tracing"]
8+
rabbitmq_conf_tcp_listeners_address : "0.0.0.0"
9+
10+
rabbitmq_vhost_definitions :
11+
- name : "vhost_cluster1"
12+
- name : "ha.cluster"
13+
14+
rabbitmq_users_definitions :
15+
- vhost : "vhost_cluster1"
16+
user : cluster1
17+
password : "password"
18+
force : no
19+
20+
- vhost : "/"
21+
user : "admin"
22+
password : "password"
23+
force : no
24+
tags : ['administrator']
25+
rabbitmq_clustering : true
26+
rabbitmq_cluster_group : "rabbitmq-cluster"
27+
rabbitmq_cluster_post_fix_domain : ""
28+
rabbitmq_erlang_cookie : "MYCOOKIE"
29+
rabbitmq_cluster_debug : true
30+
31+
# HA Policy anythin prefixed with ha. will be mirrored on all nodes
32+
rabbitmq_policy_configuration :
33+
- name : "high availability policy"
34+
vhost : "/"
35+
pattern : "^ha\\."
36+
tags : '{"ha-mode":"all"}'
37+
38+
rabbitmq_cluster_api_user : "api-automation"
39+
rabbitmq_cluster_api_password : "password"
40+
41+
roles:
42+
- role: rabbitmq

0 commit comments

Comments
 (0)