This repository has been archived by the owner on Jul 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathVagrantfile
60 lines (50 loc) · 1.97 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure('2') do |config|
# this same file is used for ansible inventory
inventory_path = 'inventory/vagrant'
inventory = YAML.load_file(inventory_path)
ansible_hosts = inventory['all']['hosts']
# delete status = absent
ansible_hosts.map do |name, vars|
# skip hosts marked as absent
ansible_hosts.delete(name) if ( vars['state'] == 'absent' )
end
ansible_limit = ansible_hosts.map{ | host_name, host | "#{host_name}" }.join(',') || 'all'
ansible_hosts.each_with_index do | (host_name, host_vars), index|
config.vm.define host_name do |host|
# setup box image for each host
host.vm.box = host_vars['vagrant_box_image']
host.vm.box_version = host_vars['vagrant_box_version']
# configure the virtual machine
host.vm.provider 'virtualbox' do |vb|
vb.name = host_name
vb.memory = host_vars['memory']
vb.cpus = host_vars['cpus']
vb.linked_clone = true
end
# configure network
host.vm.hostname = host_name
host.vm.network 'private_network', ip: host_vars['ansible_ip']
host.hostsupdater.aliases = host_vars['aliases']
host.ssh.insert_key = false
host.vm.synced_folder '.', '/vagrant', disabled: true
# only provision the last host, ansible will manage all hosts
if index == (ansible_hosts.size-1)
host.vm.provision 'ansible' do |ansible|
ansible.compatibility_mode = '2.0'
ansible.inventory_path = inventory_path
# ensure roles installed
ansible.galaxy_role_file = 'requirements.yml'
ansible.verbose = 'v'
ansible.limit = ansible_limit
ansible.playbook = 'setup.yml'
end
end
end
end
end