Skip to content

Commit

Permalink
Merge pull request #2 from hellofresh/fix/cluster_fixes
Browse files Browse the repository at this point in the history
Fix/cluster fixes
  • Loading branch information
ahelal authored Jul 12, 2016
2 parents bd6d8f2 + 2250ac2 commit 75cbd35
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 13 deletions.
49 changes: 42 additions & 7 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,65 @@ provisioner:
use_instance_name : true
groups :
rabbitmq-cluster :
- "cluster-1-docker-u14"
- "cluster-2-docker-u14"
- "cluster-3-docker-u14"
- "cluster1.192.168.110.10.xip.io"
- "cluster2.192.168.110.20.xip.io"
# - "cluster-3-docker-u14"
platforms:
- name : docker-u14
driver_config :
image : quay.io/hellofresh/kitchen-base
platform : ubuntu
driver :
name : docker
socket : unix:///var/run/docker.sock
use_sudo : false

suites :
- name : standalone
provisioner :
playbook : "test/integration/standalone/standalone.yml"
verifier :
patterns : [ test/integration/standalone/serverspec/*_spec.rb ]
driver_config :
run_options : "-p 192.168.99.100:22:22"

- name : cluster_1
- name : cluster1
provisioner :
playbook : "test/integration/cluster_1/cluster_1.yml"
inventory_hostname: cluster1.192.168.110.10.xip.io
verifier :
patterns : [ test/integration/cluster_1/serverspec/*_spec.rb ]
driver_config :
run_options : --ip=172.17.0.11
run_options : "--net cluster_network --ip=192.168.110.10"
publish_all : true
hostname : cluster1
instance_name : cluster1
# links :
# - "cluster_2:cluster_2"
# - "cluster_3:cluster_3"

- name : cluster2.192.168.110.20.xip.io
provisioner :
playbook : "test/integration/cluster_2/cluster_2.yml"
inventory_hostname: cluster2.192.168.120.10.xip.io
verifier :
patterns : [ test/integration/cluster_2/serverspec/*_spec.rb ]
driver_config :
run_options : "--net cluster_network --ip=192.168.110.20"
publish_all : true
hostname : cluster2
instance_name : cluster2
# links :
# - "cluster_1:cluster_1"
# - "cluster_3:cluster_3"

- name : cluster3
provisioner :
playbook : "test/integration/cluster_3/cluster_3.yml"
verifier :
patterns : [ test/integration/cluster_3/serverspec/*_spec.rb ]
driver_config :
instance_name : cluster3
publish_all : true
# links :
# - "cluster_1:cluster_1"
# - "cluster_2:cluster_2"

2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ source 'https://rubygems.org'
#gem 'net-ssh','~> 2.9'
# Could
gem 'kitchen-verifier-serverspec','~> 0.5.0'
gem 'kitchen-ansiblepush'
gem 'kitchen-ansiblepush', :git => 'https://github.com/ahelal/kitchen-ansiblepush', :ref => "feb8c904e600bab0361d1a287d3fa307a1da1bb1"
gem 'kitchen-docker'
gem 'serverspec'
4 changes: 3 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ rabbitmq_cluster_api_user : "api-automation"
rabbitmq_cluster_api_password : "api-password"

# How to get the IPs of cluster
rabbitmq_clustering_resolve_names : "ansible" # ['ansible', dns]
rabbitmq_clustering_resolve_names : "dns" # ['no', dns]

## Probably dont need to change that stuff
### Construct a regex to match group before .
rabbitmq_cluster_post_fix_domain_regex_replace: "([^.]*).*"
# Print extra message related to inventory
rabbitmq_cluster_debug : false
#
rabbit_cluster_nodes_version : []

24 changes: 23 additions & 1 deletion tasks/cluster/checks.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
---

- name: cluster | check cluster group
- name: check | cluster group should be valid
fail:
msg="Your configuration is not valid 'rabbitmq_cluster_group' varaible with value '{{ rabbitmq_cluster_group }}' is not valid group."
when: "{{ groups[rabbitmq_cluster_group] is not defined }}"

- name: check | get rabbitmq version in each node in the cluster
shell: rabbitmqctl status|grep "{rabbit,\"RabbitMQ\"" | cut -d, -f3 | cut -d "\"" -f2
delegate_to: "{{ item }}"
changed_when: false
run_once: true
with_items: "{{ groups[rabbitmq_cluster_group] }}"
register: cluster_versions_command

- name: check | Create a list of nodes and versions
set_fact:
rabbit_cluster_nodes_version: "{{ [{ 'node': item.item, 'version': item.stdout }] + rabbit_cluster_nodes_version }}"
with_items: "{{ cluster_versions_command.results }}"
run_once: true

# Filter out node values that are not the same version then compae with original node version
# if lists dont match then we have different versions in our cluster
- name: check | Fail if version in cluster dont match
fail:
msg="Rabbiqmq version in cluster dont match. Node versions = {{rabbit_cluster_nodes_version }}"
run_once: true
when: "{{ rabbit_cluster_nodes_version | selectattr('version', 'equalto', rabbit_cluster_nodes_version[0]['version']) | list != rabbit_cluster_nodes_version }}"
5 changes: 3 additions & 2 deletions tasks/cluster/hostnames.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---

# RabbitMQ uses short names for hosts. We need to make them resolvable along all the clusters
- name: hostnames | resolve cluster IPs with DNS
debug:
Expand All @@ -12,7 +13,7 @@
- name: hostnames | manage cluster nodes in host file
lineinfile:
dest="/etc/hosts"
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"
regexp="^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}\s{{ item.1.split('.')[0] }} {{ '#' }}ansible-rabbitmq-role"
line="{{ rabbitmq_server_ips['results'][item.0]['msg'] }}{{'\t'}}{{ item.1.split('.')[0] }} {{ '#' }}ansible-rabbitmq-role"
state="present"
with_items: "{{ groups[rabbitmq_cluster_group] | difference([inventory_hostname]) }}"
with_indexed_items: "{{ groups[rabbitmq_cluster_group] | difference([inventory_hostname]) }}"
1 change: 1 addition & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- block:
- include: cluster/checks.yml
- include: cluster/hostnames.yml
when: rabbitmq_clustering_resolve_names != "no"
- include: cluster/erlang_cookie.yml
- include: cluster/cluster.yml
when: rabbitmq_clustering
35 changes: 35 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh
set -e

if [ "$1" == "run" ]; then
echo ""
echo "**** Running tests ****"
echo "-> Docker creating userdefined network"
docker network create --subnet 192.168.110.0/24 cluster_network

echo "-> Create cluster1"
bundle exec kitchen create cluster1

echo "-> Create cluster2"
bundle exec kitchen create cluster2

elif [ "$1" == "destroy" ]; then
set +e
echo ""
echo "**** Running destroy ****"

echo "-> Destroy cluster1 "
bundle exec kitchen destroy cluster1
docker rm cluster1

echo "-> Destroy cluster2 "
bundle exec kitchen destroy cluster2
docker rm cluster2

echo "-> Docker remove userdefined network"
docker network rm cluster_network
else
echo "unsupported option '$1'"
echo "usage [ run | destroy ]"
exit 1
fi
1 change: 1 addition & 0 deletions test/integration/cluster_1/cluster_1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- hosts: all
become: true
vars:
rabbitmq_clustering_resolve_names : "no"
rabbitmq_ssl : false
#rabbitmq_plugins : ["rabbitmq_management","rabbitmq_tracing"]
rabbitmq_conf_tcp_listeners_address : "0.0.0.0"
Expand Down
43 changes: 42 additions & 1 deletion test/integration/cluster_2/cluster_2.yml
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
cluster_2.yml
---

- hosts: all
become: true
vars:
rabbitmq_ssl : false
#rabbitmq_plugins : ["rabbitmq_management","rabbitmq_tracing"]
rabbitmq_conf_tcp_listeners_address : "0.0.0.0"

rabbitmq_vhost_definitions :
- name : "vhost_cluster1"
- name : "ha.cluster"

rabbitmq_users_definitions :
- vhost : "vhost_cluster1"
user : cluster1
password : "password"
force : no

- vhost : "/"
user : "admin"
password : "password"
force : no
tags : ['administrator']
rabbitmq_clustering : true
rabbitmq_cluster_group : "rabbitmq-cluster"
rabbitmq_cluster_post_fix_domain : ""
rabbitmq_erlang_cookie : "MYCOOKIE"
rabbitmq_cluster_debug : true

# HA Policy anythin prefixed with ha. will be mirrored on all nodes
rabbitmq_policy_configuration :
- name : "high availability policy"
vhost : "/"
pattern : "^ha\\."
tags : '{"ha-mode":"all"}'

rabbitmq_cluster_api_user : "api-automation"
rabbitmq_cluster_api_password : "password"

roles:
- role: rabbitmq

0 comments on commit 75cbd35

Please sign in to comment.