Last active
March 15, 2019 12:53
-
-
Save Grin941/61c9dce1f08c2d37d2a2fc5cf3612c3d to your computer and use it in GitHub Desktop.
Standard Vagrant VM
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
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
hosts = { | |
"grin941JobApi" => "192.168.33.16", | |
"grin941Server" => "192.168.33.15" | |
} | |
Vagrant.configure("2") do |config| | |
hosts.each do |name, ip| | |
# Change VirtualBox GUI name | |
config.vm.define "%s" % name do |subconfig| | |
subconfig.vm.box = "ubuntu/bionic64" | |
# Define hostname | |
subconfig.vm.hostname = "%s" % name | |
# Disable automatic box update checking. If you disable this, then | |
# boxes will only be checked for updates when the user runs | |
# `vagrant box outdated`. This is not recommended. | |
# config.vm.box_check_update = false | |
# Create a forwarded port mapping which allows access to a specific port | |
# within the machine from a port on the host machine. In the example below, | |
# accessing "localhost:8080" will access port 80 on the guest machine. | |
# NOTE: This will enable public access to the opened port | |
# config.vm.network "forwarded_port", guest: 80, host: 8080 | |
# Create a forwarded port mapping which allows access to a specific port | |
# within the machine from a port on the host machine and only allow access | |
# via 127.0.0.1 to disable public access | |
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1" | |
# Create a private network, which allows host-only access to the machine | |
# using a specific IP. | |
subconfig.vm.network "private_network", ip: "%s" % ip | |
# Create a public network, which generally matched to bridged network. | |
# Bridged networks make the machine appear as another physical device on | |
# your network. | |
# config.vm.network "public_network" | |
# Share an additional folder to the guest VM. The first argument is | |
# the path on the host to the actual folder. The second argument is | |
# the path on the guest to mount the folder. And the optional third | |
# argument is a set of non-required options. | |
# config.vm.synced_folder "../data", "/vagrant_data" | |
subconfig.vm.provider "virtualbox" do |vb| | |
# # Display the VirtualBox GUI when booting the machine | |
# vb.gui = true | |
# | |
# # Customize Vagrant box name: | |
vb.name = "%s" % name | |
# # Customize the amount of memory on the VM: | |
vb.memory = "4096" | |
vb.cpus = "2" | |
end | |
subconfig.vm.provision "shell" do |s| | |
# Copy local machine ssh pub_key to remote machine | |
ssh_pub_key = File.readlines("#{Dir.home}/.ssh/id_rsa.pub").first.strip | |
s.inline = <<-SHELL | |
echo #{ssh_pub_key} >> /home/vagrant/.ssh/authorized_keys | |
echo #{ssh_pub_key} >> /root/.ssh/authorized_keys | |
sudo apt update | |
sudo apt upgrade | |
sudo apt install -y python | |
SHELL | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment