Fix title in readme
[obnox/vagrant/vagrant-samba-fs.git] / Vagrantfile
1 # -*- mode: ruby -*-
2 # vi: set ft=ruby :
3
4 ENV['VAGRANT_DEFAULT_PROVIDER'] = 'lxc'
5
6 VAGRANTFILE_API_VERSION = 2
7
8
9 require 'yaml'
10
11 #
12 # Defaults for Configuration data.
13 # Will be overridden from the settings file
14 # and (possibly later) from commandline parameters.
15 #
16
17 net_default = {
18   :type   => 'veth',
19   :flags  => 'up',
20   :hwaddr => '',
21   :name   => '',
22   :ipv4   => '',
23   :ipv6   => '',
24 }
25
26 network_opts = [ :type, :link, :flags, :hwaddr, :name, :ipv4, :ipv6 ]
27
28 vms = [
29   {
30     :hostname => 'smbfs1',
31     :box => 'obnox/fedora23-64-lxc',
32     #:box => 'local-fedora-rawhide-64',
33     :container_name => 'smbfs1',
34     :networks => [
35       #{
36       #  :link => 'virbr1',
37       #  :ipv4 => ctdb[:nodes_ips][0],
38       #},
39       #{
40       #  :link => 'virbr2',
41       #  #:ipv4 => '10.111.222.201',
42       #},
43     ],
44   },
45 ]
46
47 #
48 # Load the config, if it exists,
49 # possibly override with commandline args,
50 # (currently none supported yet)
51 # and then store the config.
52 #
53
54 projectdir = File.expand_path File.dirname(__FILE__)
55 f = File.join(projectdir, 'vagrant.yaml')
56 if File.exists?(f)
57   settings = YAML::load_file f
58
59   if settings[:vms].is_a?(Array)
60     vms = settings[:vms]
61   end
62   puts "Loaded settings from #{f}."
63 end
64
65 # TODO(?): ARGV-processing
66
67 settings = {
68   :vms  => vms,
69 }
70
71 File.open(f, 'w') do |file|
72   file.write settings.to_yaml
73 end
74 puts "Wrote settings to #{f}."
75
76 # apply net defaults:
77
78 vms.each do |vm|
79   vm[:networks].each do |net|
80     net_default.keys.each do |key|
81       if not net.has_key?(key)
82         net[key] = net_default[key]
83       end
84     end
85   end
86 end
87
88
89 PROVISION_SCRIPT = <<SCRIPT
90 dnf -y makecache fast
91 dnf -y install samba
92 SCRIPT
93
94
95 #
96 # The vagrant machine definitions
97 #
98
99 Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
100
101   if Vagrant.has_plugin?("vagrant-cachier")
102     config.cache.scope = :box
103   end
104
105   vms.each do |machine|
106     config.vm.define machine[:hostname] do |node|
107       node.vm.box = machine[:box]
108       node.vm.hostname = machine[:hostname]
109       node.vm.provider :lxc do |lxc|
110         lxc.container_name = machine[:container_name]
111
112         machine[:networks].each do |net|
113           network_opts.each do |key|
114             if not net[key] == ''
115               lxc.customize "network.#{key}", net[key]
116             end
117           end
118         end
119       end
120       #node.vm.synced_folder "shared/", "/shared"
121     end
122   end
123
124   config.vm.provision :shell, inline: PROVISION_SCRIPT
125
126 end