-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
84 lines (70 loc) · 2.83 KB
/
Vagrantfile
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
# -*- mode: ruby -*-
# vi: set ft=ruby :
# List of supported operating systems
SUPPORTED_OS = {
"ubuntu2010" => {box: "generic/ubuntu2010", bootstrap_os: "ubuntu", user: "vagrant"},
"centos8" => {box: "generic/centos8", bootstrap_os: "centos", user: "vagrant"}
}
# Vagrant instance management
$os = "centos8"
$num_instances = 1
$instance_name_prefix = "n8n"
$vm_memory = 4096
$vm_cpus = 2
$subnet = "10.0.0.1" # For 10.0.0.1X
$box = SUPPORTED_OS[$os][:box]
# Ansible provisioner
$playbook = "n8n.yml"
# if $inventory is not set, try to use example
$inventory = File.join(File.dirname(__FILE__), "inventory") if ! $inventory
# if $inventory has a hosts file use it, otherwise copy over vars etc
# to where vagrant expects dynamic inventory to be.
if ! File.exist?(File.join(File.dirname($inventory), "hosts"))
$vagrant_ansible = File.join(File.dirname(__FILE__), ".vagrant", "provisioners", "ansible")
FileUtils.mkdir_p($vagrant_ansible) if ! File.exist?($vagrant_ansible)
if ! File.exist?(File.join($vagrant_ansible,"inventory"))
FileUtils.ln_s($inventory, File.join($vagrant_ansible,"inventory"))
end
end
Vagrant.configure("2") do |config|
# Configure hosts file
config.hostmanager.enabled = true
config.hostmanager.manage_host = true
config.hostmanager.manage_guest = true
config.hostmanager.ignore_private_ip = false
config.hostmanager.include_offline = true
# always use Vagrants insecure key
config.ssh.insert_key = false
config.ssh.username = SUPPORTED_OS[$os][:user]
# Configure box
config.vm.box = $box
(1..$num_instances).each do |i|
config.vm.provider "virtualbox" do |vb|
vb.memory = $vm_memory
vb.cpus = $vm_cpus
end
config.vm.define vm_name = "%s%02d" % [$instance_name_prefix, i] do |server|
config.vm.hostname = vm_name
server.vm.network "private_network", ip: "#{$subnet}#{i}"
# Provision
config.vm.provision "shell", path: "provision.sh"
# config.vm.provision "file", source: "~/.ssh/id_rsa.pub", destination: "/home/vagrant/.ssh/authorized_keys"
# Only execute the Ansible provisioner when all the machines are up and ready
if i == $num_instances
config.vm.provision "ansible" do |ansible|
ansible.compatibility_mode = "2.0"
ansible.playbook = $playbook
if File.exist?(File.join(File.dirname($inventory), "hosts"))
ansible.inventory_path = $inventory
end
ansible.become = true
ansible.limit = "all"
ansible.host_key_checking = false
ansible.groups = {
"n8n" => ["#{$instance_name_prefix}0[1:#{$num_instances}]"]
}
end
end
end
end
end