Add roles and variables
This commit is contained in:
99
vagrant/Vagrantfile
vendored
99
vagrant/Vagrantfile
vendored
@@ -1,56 +1,51 @@
|
||||
num_workers = 1
|
||||
|
||||
nodes = [
|
||||
{ :hostname => 'ansible-manager', :ip => '192.168.56.9', :ram => 256, :cpus => 1 },
|
||||
{ :hostname => 'swarm-master-1', :ip => '192.168.56.10', :ram => 256, :cpus => 1 },
|
||||
# { :hostname => 'swarm-master-2', :ip => '192.168.56.11', :ram => 256, :cpus => 1 },
|
||||
# { :hostname => 'swarm-worker-1', :ip => '192.168.56.12', :ram => 256, :cpus => 1 },
|
||||
# { :hostname => 'swarm-worker-2', :ip => '192.168.56.13', :ram => 1024, :cpus => 1 }
|
||||
{ hostname: 'swarm-master', ip: '192.168.56.10', ram: 256, cpus: 1, groups: ['swarm_master'] }
|
||||
]
|
||||
|
||||
Vagrant.configure("2") do |config|
|
||||
# config.ssh.insert_key = false
|
||||
# config.ssh.forward_agent = true
|
||||
config.vm.provision "ansible" do |ansible|
|
||||
ansible.playbook = "setup.yml"
|
||||
# ansible.inventory_path = "../ansible/inventory"
|
||||
# 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.box_version = "20250415.336224"
|
||||
|
||||
# node_config.ssh.private_key_path = "../keys/access"
|
||||
|
||||
# node_config.vm.provision "shell", inline: <<-SHELL
|
||||
# mkdir -p /home/vagrant/.ssh
|
||||
# echo '$(cat ../keys/access.pub)' >> /home/vagrant/.ssh/authorized_keys
|
||||
# chown -R vagrant:vagrant /home/vagrant/.ssh
|
||||
# chmod 700 /home/vagrant/.ssh
|
||||
# chmod 600 /home/vagrant/.ssh/authorized_keys
|
||||
# SHELL
|
||||
# config.vm.provision "shell" do |s|
|
||||
# ssh_pub_key = File.readlines("../keys/access.pub").first.strip
|
||||
# s.inline = <<-SHELL
|
||||
# echo #{ssh_pub_key} >> /home/vagrant/.ssh/authorized_keys
|
||||
# echo #{ssh_pub_key} >> /root/.ssh/authorized_keys
|
||||
# SHELL
|
||||
# end
|
||||
# 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
|
||||
|
||||
# config.vm.define "ansible-manager" do |ansible|
|
||||
# ansible.vm.provision "file", source: "../ansible", destination: "$HOME"
|
||||
# ansible.vm.provision "shell", path: "ansible.sh"
|
||||
# ansible.vm.provision "shell", inline: "echo 'hello ansible!'"
|
||||
# end
|
||||
(1..num_workers).each do |i|
|
||||
nodes << {
|
||||
hostname: "swarm-worker-#{i}",
|
||||
ip: "192.168.56.#{10 + i}",
|
||||
ram: 256,
|
||||
cpus: 1,
|
||||
groups: ['swarm_workers']
|
||||
}
|
||||
end
|
||||
|
||||
Vagrant.configure('2') do |config|
|
||||
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.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.box = 'generic/archlinux64'
|
||||
# node_config.vm.box_version = "20250415.336224"
|
||||
|
||||
# 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
|
||||
|
||||
Reference in New Issue
Block a user