File: Vagrantfile

package info (click to toggle)
resource-agents-paf 2.2.1-1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 340 kB
  • sloc: perl: 1,811; sh: 208; makefile: 27
file content (109 lines) | stat: -rw-r--r-- 4,207 bytes parent folder | download
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
require 'ipaddr'
require 'yaml'

#ENV['VAGRANT_NO_PARALLEL'] = 'yes' # uncomment to forbid parallel execution

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 "./ssh/id_rsa.pub" in your "~<ssh_login>/.ssh/authorized_keys"
master_ip = '10.20.30.5' # vIP assigned to master
pg_nodes  = 'srv1', 'srv2', 'srv3' # first will be primary
log_node  = 'log-sink'
vm_prefix = 'paf_c7'

if File.file?('vagrant.yml') and ( custom = YAML.load_file('vagrant.yml') )
    pgver     = custom['pgver']     if custom.has_key?('pgver')
    hapass    = custom['hapass']    if custom.has_key?('hapass')
    ssh_login = custom['ssh_login'] if custom.has_key?('ssh_login')
    master_ip = custom['master_ip'] if custom.has_key?('master_ip')
    pg_nodes  = custom['pg_nodes']  if custom.has_key?('pg_nodes')
    log_node  = custom['log_node']  if custom.has_key?('log_node')
    vm_prefix = custom['vm_prefix'] if custom.has_key?('vm_prefix')
end

Vagrant.configure(2) do |config|

    pgdata     = "/var/lib/pgsql/#{pgver}/data"
    next_ip    = IPAddr.new(master_ip).succ
    host_ip    = (IPAddr.new(master_ip) & "255.255.255.0").succ.to_s
    nodes_ips  = {}

    ( pg_nodes + [ log_node ] ).each do |node|
        nodes_ips[node] = next_ip.to_s
        next_ip = next_ip.succ
    end

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

    # https://vagrantcloud.com/search.
    config.vm.box = 'centos/7'

    # hardware and host settings
    config.vm.provider 'libvirt' do |lv|
        lv.cpus = 1
        lv.memory = 512
        lv.watchdog model: 'i6300esb'
        lv.default_prefix = vm_prefix
    end

    # disable default share
    config.vm.synced_folder ".", "/vagrant", disabled: true

    # allow root@vm to ssh to ssh_login@network_1
    config.vm.synced_folder 'ssh', '/root/.ssh', type: 'rsync',
        owner: 'root', group: 'root',
        rsync__args: [ "--verbose", "--archive", "--delete", "--copy-links", "--no-perms" ]

    # system setup for all ndoes
    (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', path: 'provision/system.bash',
                args: [ node ] + nodes_ips.keys.map {|n| "#{n}=#{nodes_ips[n]}"},
                preserve_order: true
        end
    end

    # setup rsyslog to collect logs from other node on log-sink
    config.vm.define log_node do |conf|
        conf.vm.provision 'rsyslog-setup', type: 'shell', path: 'provision/log_sink.bash'
    end

    # common postgresql+pacemaker installation and setup
    pg_nodes.each do |node|
        config.vm.define node do |conf|
            conf.vm.provision 'base-common', type: 'shell', path: 'provision/base-common.bash',
                args: [ pgver, hapass, master_ip ],
                preserve_order: true
        end
    end

    # build primary pgsql instance
    config.vm.define pg_nodes.first, primary:true do |conf|
        conf.vm.provision 'pgsql-primary', type: 'shell',
            path: 'provision/pgsql-primary.bash',
            args: [ pgver, pgdata, master_ip, pg_nodes.first ],
            preserve_order: true
    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, pgdata, master_ip, node ], run: 'never'
        end
    end

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

    # cluster test suite setup. Use "vagrant up --provision-with=cts"
    config.vm.provision 'cts', type: 'shell', path: 'provision/cts.bash', run: 'never'
end