Created
September 22, 2020 08:42
-
-
Save asquelt/373124a454bc61d24b64700d2836e0bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vagrant.configure("2") do |config| | |
config.hostmanager.enabled = true | |
config.hostmanager.manage_host = false | |
config.hostmanager.manage_guest = true | |
#config.hostmanager.ignore_private_ip = false | |
config.hostmanager.include_offline = true | |
servers=[ | |
{ | |
:hostname => "db1", | |
:box => "centos/7", | |
:ip => "192.168.56.100" | |
}, | |
{ | |
:hostname => "db2", | |
:box => "centos/7", | |
:ip => "192.168.56.101" | |
}, | |
{ | |
:hostname => "web1", | |
:box => "bento/ubuntu-18.04", | |
:ip => "192.168.56.102" | |
}, | |
{ | |
:hostname => "web2", | |
:box => "bento/ubuntu-18.04", | |
:ip => "192.168.56.103" | |
}, | |
{ | |
:hostname => "control", | |
:box => "centos/7", | |
:ip => "192.168.56.111" | |
} | |
] | |
servers.each do |machine| | |
config.vm.define machine[:hostname] do |node| | |
node.vm.box = machine[:box] | |
node.vm.hostname = machine[:hostname] | |
node.vm.network :private_network, ip: machine[:ip] | |
#node.vm.network "forwarded_port", guest: 22, host: machine[:ssh_port], id: "ssh" | |
node.vm.provider :virtualbox do |v| | |
v.customize ["modifyvm", :id, "--memory", 512] | |
v.customize ["modifyvm", :id, "--name", machine[:hostname]] | |
end | |
end | |
end | |
id_rsa_key_pub = File.read(File.join(Dir.home, ".ssh", "id_rsa.pub")) | |
config.vm.provision :shell, | |
:inline => "echo 'appending SSH public key to ~vagrant/.ssh/authorized_keys' && echo '#{id_rsa_key_pub }' >> /home/vagrant/.ssh/authorized_keys && chmod 600 /home/vagrant/.ssh/authorized_keys" | |
config.ssh.insert_key = false | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment