71 lines
1.6 KiB
Ruby
71 lines
1.6 KiB
Ruby
num_workers = 1
|
|
|
|
nodes = [
|
|
{
|
|
hostname: 'swarm-master',
|
|
ip: '192.168.56.10',
|
|
ram: 1024,
|
|
cpus: 1,
|
|
groups: ['swarm_master']
|
|
},
|
|
{
|
|
hostname: 'swarm-worker-storage',
|
|
ip: '192.168.56.11',
|
|
ram: 512,
|
|
cpus: 1,
|
|
# groups: ['swarm_workers','storage']
|
|
groups: %w[swarm_workers storage]
|
|
}
|
|
]
|
|
|
|
(1..num_workers).each do |i|
|
|
nodes << {
|
|
hostname: "swarm-worker-#{i}",
|
|
ip: "192.168.56.#{11 + i}",
|
|
ram: 256,
|
|
cpus: 1,
|
|
groups: ['swarm_workers']
|
|
}
|
|
end
|
|
|
|
Vagrant.configure('2') do |config|
|
|
# config.vbguest.auto_update = true
|
|
|
|
groups = {}
|
|
nodes.each do |node|
|
|
node[:groups].each do |group|
|
|
groups[group] ||= []
|
|
groups[group] << node[:hostname]
|
|
end
|
|
end
|
|
|
|
config.vm.provision 'ansible' do |ansible|
|
|
ansible.playbook = 'setup.yml'
|
|
ansible.config_file = 'ansible.cfg'
|
|
ansible.groups = groups
|
|
|
|
# ansible.verbose = true
|
|
# ansible.limit = "all"
|
|
# ansible.raw_arguments = ["--timeout=60"]
|
|
end
|
|
|
|
nodes.each do |node|
|
|
puts "Provisioning node: #{node[:hostname]}"
|
|
config.vm.define node[:hostname] do |node_config|
|
|
node_config.vm.hostname = node[:hostname]
|
|
node_config.vm.box = 'debian/bullseye64'
|
|
# node_config.vm.synced_folder "./data", "/vagrant_data"
|
|
|
|
# node_config.vm.box_version = "20250415.336224"
|
|
# node_config.vm.box = 'generic/archlinux64'
|
|
|
|
node_config.vm.network 'private_network', ip: node[:ip]
|
|
node_config.vm.provider 'virtualbox' do |vb|
|
|
vb.name = node[:hostname]
|
|
vb.memory = node[:ram]
|
|
vb.cpus = node[:cpus]
|
|
end
|
|
end
|
|
end
|
|
end
|