Skip to content

Commit

Permalink
extra: refactor 3nodes-haproxy vagrant file
Browse files Browse the repository at this point in the history
  • Loading branch information
ioguix committed Sep 24, 2020
1 parent 0134f91 commit 2fbbd69
Show file tree
Hide file tree
Showing 11 changed files with 519 additions and 589 deletions.
24 changes: 7 additions & 17 deletions extra/vagrant/3nodes-haproxy/Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
export VAGRANT_BOX_UPDATE_CHECK_DISABLE=1
export VAGRANT_CHECKPOINT_DISABLE=1

.PHONY: all create_vm postgresql pgsql_replicas pacemaker prov clean check validate cts pcmk-stop
.PHONY: all up pgsql pacemaker cts clean check validate pcmk-stop

all: up

all: create_vm postgresql pgsql_replicas pacemaker cluster

create_vm:
up:
vagrant up

postgresql: pcmk-stop
vagrant up --provision-with=postgresql

pgsql_replicas: pcmk-stop
vagrant up --provision-with=pgsql-replicas
pgsql: pcmk-stop
vagrant provision --provision-with=pgsql

pacemaker:
vagrant up --provision-with=pacemaker

cluster:
vagrant up --provision-with=cluster-setup

prov:
vagrant up --provision
vagrant provision --provision-with=pacemaker

clean:
vagrant destroy -f
Expand All @@ -37,7 +27,7 @@ validate:
fi

cts:
vagrant up --provision-with=cts
vagrant provision --provision-with=cts

pcmk-stop:
vagrant ssh -c 'if [ -f "/etc/corosync/corosync.conf" ]; then sudo pcs cluster stop --all --wait; fi'
Expand Down
109 changes: 41 additions & 68 deletions extra/vagrant/3nodes-haproxy/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ require 'yaml'
ENV["LANG"] = "C"
ENV["LC_ALL"] = "C"

boxname = 'centos/7' # vagrant box to use
pgver = '11' # pg version to use
hapass = 'hapass' # password for sys user hacluster
ssh_login = 'root' # ssh login to connect to the host when fencing a VM.
# put "./provision/id_rsa.pub" in your "~<ssh_login>/.ssh/authorized_keys"
base_ip = '10.20.30.5' # Base IP address to compute other ones
pg_nodes = 'srv1', 'srv2', 'srv3' # first will be primary
log_node = 'log-sink' # name of the node receiving logs
vm_prefix = 'paf_vm' # VM prefix in libvrit
rhel_user = '' # RHEL user account
rhel_pass = '' # RHEL user account password
boxname = 'centos/7' # vagrant box to use
pgver = '12' # pg version to use
hapass = 'hapass' # password for sys user hacluster
ssh_login = 'root' # ssh login to connect to the host when fencing a VM.
# put "./provision/id_rsa.pub" in your "~<ssh_login>/.ssh/authorized_keys"
base_ip = '10.20.30.50' # Base IP address to compute other ones
vm_prefix = 'paf_3nHP' # VM prefix in libvrit
rhel_user = '' # RHEL user account
rhel_pass = '' # RHEL user account password
pg_nodes = 'srv1', 'srv2', 'srv3' # first will be primary
log_node = 'log-sink' # name of the node receiving logs


if File.file?('vagrant.yml') and ( custom = YAML.load_file('vagrant.yml') )
boxname = custom['boxname'] if custom.has_key?('boxname')
Expand All @@ -33,7 +34,7 @@ end
Vagrant.configure(2) do |config|

############################################################################
# computes variables
# computes IPs

pgdata = "/var/lib/pgsql/#{pgver}/data"
next_ip = IPAddr.new(base_ip).succ
Expand All @@ -48,6 +49,13 @@ Vagrant.configure(2) do |config|
############################################################################
# general vagrant setup

# RHEL registration when needed
if Vagrant.has_plugin?('vagrant-registration')
config.registration.unregister_on_halt = false
config.registration.username = rhel_user
config.registration.password = rhel_pass
end

# don't mind about insecure ssh key
config.ssh.insert_key = false

Expand All @@ -63,91 +71,56 @@ Vagrant.configure(2) do |config|
lv.qemu_use_session = false
end

# disable default share
# sync the root of sources
config.vm.synced_folder ".", "/vagrant", disabled: true

config.vm.synced_folder "../../..", "/vagrant", type: "rsync",
rsync__exclude: [ ".git/" ]

config.vm.define pg_nodes.first, primary: true

############################################################################
# system setup for all nodes

config.vm.define pg_nodes.first, primary: true
config.vm.provision 'file', source: 'provision/id_rsa', destination: '/home/vagrant/.ssh/id_rsa'
config.vm.provision 'file', source: 'provision/id_rsa.pub', destination: '/home/vagrant/.ssh/id_rsa.pub'

(pg_nodes + [log_node]).each do |node|
config.vm.define node do |conf|
conf.vm.network 'private_network', ip: nodes_ips[node]
conf.vm.provision 'system-setup', type: 'shell',
conf.vm.provision 'system', type: 'shell',
path: 'provision/system.bash',
args: [ node, rhel_user, rhel_pass ] + nodes_ips.keys.map {|n| "#{n}=#{nodes_ips[n]}"},
args: [ node, pgver, hapass, log_node ] +
nodes_ips.keys.map {|n| "#{n}=#{nodes_ips[n]}"},
preserve_order: true
end
end


############################################################################
# setup rsyslog to collect logs
(pg_nodes + [log_node]).each do |node|
config.vm.define node do |conf|
conf.vm.provision 'rsyslog-setup', type: 'shell',
path: 'provision/rsyslog.bash',
args: [ log_node ],
preserve_order: true
end
end

############################################################################
# setup haproxy
# build pgsql instances
pg_nodes.each do |node|
config.vm.define node do |conf|
conf.vm.provision 'haproxy-setup', type: 'shell',
path: 'provision/haproxy.bash',
conf.vm.provision 'pgsql', type: 'shell',
path: 'provision/pgsql.bash',
args: [ node, pgver, pgdata, pg_nodes.first ],
preserve_order: true
end
end

############################################################################
# postgresql installation and setup
pg_nodes.each do |node|
config.vm.define node do |conf|
conf.vm.provision 'postgresql', type: 'shell',
path: 'provision/postgresql.bash',
args: [ pgver, pg_nodes.first, pgdata ],
preserve_order: true
end
end

# replicas setup. Use "vagrant up --provision-with=pgsql-replicas"
pg_nodes[1..-1].each do |node|
config.vm.define node do |conf|
conf.vm.provision 'pgsql-replicas', type: 'shell',
path: 'provision/pgsql-replicas.bash',
args: [ pgver, node, pgdata ],
run: 'never'
end
end

############################################################################
# cluster setup. Use "vagrant up --provision-with=pacemaker"
# cluster setup
pg_nodes.each do |node|
config.vm.define node do |conf|
conf.vm.provision 'pacemaker', type: 'shell',
path: 'provision/pacemaker.bash',
args: [ hapass ],
run: 'never'
end
end

# create the cluster. Use "vagrant up --provision-with=cluster-setup"
pg_nodes.each do |node|
config.vm.define node do |conf|
conf.vm.provision 'cluster-setup', type: 'shell',
path: 'provision/cluster.bash',
args: [ pgver, ssh_login, vm_prefix, host_ip, pgdata, hapass ] + pg_nodes,
run: 'never'
args: [ pgver, hapass, ssh_login,
vm_prefix, host_ip, pgdata ] + pg_nodes,
preserve_order: true
end
end

# cluster test suite setup. Use "vagrant up --provision-with=cts"
config.vm.provision 'cts', type: 'shell', path: 'provision/cts.bash', run: 'never'
############################################################################
# cluster test suite setup. Use "vagrant provision --provision-with=cts"
config.vm.provision 'cts', type: 'shell',
path: 'provision/cts.bash',
run: 'never'
end
102 changes: 0 additions & 102 deletions extra/vagrant/3nodes-haproxy/provision/cluster.bash

This file was deleted.

78 changes: 0 additions & 78 deletions extra/vagrant/3nodes-haproxy/provision/haproxy.bash

This file was deleted.

Loading

0 comments on commit 2fbbd69

Please sign in to comment.