This repository has been archived by the owner on Apr 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Vagrantfile.consul.rb
128 lines (108 loc) · 3.84 KB
/
Vagrantfile.consul.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Assumes a box from https://github.com/grypyrg/packer-percona
# This sets up 3 consul server nodes and 1 consul client node
require File.dirname(__FILE__) + '/lib/vagrant-common.rb'
# Node names and ips (for local VMs)
# (Amazon) aws_region is where to bring up the node
# (Amazon) Security groups are 'default' (22 open) and 'pxc' (3306, 4567-4568, 4444 open) for each respective region
# Don't worry about amazon config if you are not using that provider.
consul = {
'consul1' => {
'local_vm_ip' => '192.168.70.2',
'aws_region' => 'us-east-1',
'server_id' => 1,
'security_groups' => ['sg-c88d28ae', 'sg-126b9b6e']
},
'consul2' => {
'local_vm_ip' => '192.168.70.3',
'aws_region' => 'us-east-1',
'server_id' => 2,
'security_groups' => ['sg-c88d28ae', 'sg-126b9b6e']
},
'consul3' => {
'local_vm_ip' => '192.168.70.4',
'aws_region' => 'us-east-1',
'server_id' => 3,
'security_groups' => ['sg-c88d28ae', 'sg-126b9b6e']
}
}
client = {
'client1' => {
'local_vm_ip' => '192.168.70.10',
'aws_region' => 'us-east-1',
'security_groups' => ['sg-c88d28ae', 'sg-be6c9cc2'],
'type' => 'client'
}
}
# Use 'public' for cross-region AWS. 'private' otherwise (or commented out)
aws_ips = 'private'
if_adapter='vboxnet1'
Vagrant.configure("2") do |config|
config.vm.box = "grypyrg/centos-x86_64"
config.vm.box_version = "~> 7"
config.ssh.username = "vagrant"
config.hostmanager.enabled = false # Disable this for AWS
config.hostmanager.include_offline = true
# Create all three nodes identically except for name and ip
consul.each_pair { |name, node_params|
config.vm.define name do |node_config|
node_config.vm.hostname = name
node_config.vm.network :private_network, ip: node_params['local_vm_ip'], adaptor: if_adapter
node_config.vm.provision :hostmanager
# Forward Consul UI port
node_config.vm.network "forwarded_port", guest: 8500, host: 8500 + node_params['server_id'], protocol: 'tcp'
# Provisioners
provision_puppet( node_config, "base.pp" )
provision_puppet( node_config, "consul_server.pp" ) { |puppet|
puppet.facter = {
'datacenter' => 'dc1',
'bind_addr' => '0.0.0.0',
'node_name' => name,
'retry_join' => consul.keys.join(','),
'bootstrap_expect' => consul.length
}
}
provider_virtualbox( nil, node_config, 256 ) { |vb, override|
vb.linked_clone = true
# Override the bind_addr on vbox to use the backend network
provision_puppet( override, "consul_server.pp" ) { |puppet|
puppet.facter = {
'bind_addr' => node_params['local_vm_ip'],
'default_interface' => 'eth1'
}
}
}
provider_aws( "consul #{name}", node_config, 'm3.medium', node_params['aws_region'], node_params['security_groups'], aws_ips)
end
}
# Create clients
client.each_pair { |name, node_params|
config.vm.define name do |node_config|
node_config.vm.hostname = name
node_config.vm.network :private_network, ip: node_params['local_vm_ip'], adaptor: if_adapter
node_config.vm.provision :hostmanager
# Provisioners
provision_puppet( node_config, "base.pp" )
provision_puppet( node_config, "consul_client.pp" ) { |puppet|
puppet.facter = {
'datacenter' => 'dc1',
'bind_addr' => '0.0.0.0',
'node_name' => name,
'retry_join' => consul.keys.join(',')
}
}
provider_virtualbox( nil, node_config, 256 ) { |vb, override|
vb.linked_clone = true
# Override the bind_addr on vbox to use the backend network
provision_puppet( override, "consul_client.pp" ) { |puppet|
puppet.facter = {
'bind_addr' => node_params['local_vm_ip'],
'default_interface' => 'eth1'
}
}
}
provider_aws( "consul #{name}", node_config, 'm3.medium', node_params['aws_region'], node_params['security_groups'], aws_ips)
end
}
end