4 ENV['VAGRANT_DEFAULT_PROVIDER'] = 'lxc'
6 VAGRANTFILE_API_VERSION = 2
12 # Defaults for Configuration data.
13 # Will be overridden from the settings file
14 # and (possibly later) from commandline parameters.
26 network_opts = [ :type, :link, :flags, :hwaddr, :name, :ipv4, :ipv6 ]
30 :hostname => 's4dc-180',
31 :box => 'fgrehm/trusty64-lxc',
34 :container_name => 's4dc-180',
40 :ipv4 => '172.16.1.180',
44 # #:ipv4 => '10.111.222.201',
51 :realm => 's4ad.private',
52 :adminpass => 'Passw0rd',
53 :function_level => '2008_R2',
60 # Load the config, if it exists,
61 # possibly override with commandline args,
62 # (currently none supported yet)
63 # and then store the config.
66 projectdir = File.expand_path File.dirname(__FILE__)
67 f = File.join(projectdir, 'vagrant.yaml')
69 settings = YAML::load_file f
71 if settings[:vms].is_a?(Array)
74 puts "Loaded settings from #{f}."
77 # TODO(?): ARGV-processing
83 File.open(f, 'w') do |file|
84 file.write settings.to_yaml
86 puts "Wrote settings to #{f}."
91 vm[:networks].each do |net|
92 net_default.keys.each do |key|
93 if not net.has_key?(key)
94 net[key] = net_default[key]
101 SCRIPT_INSTALL = <<SCRIPT
106 apt-get -y install samba dnsutils
109 SCRIPT_PROVISION = <<SCRIPT
119 stop samba-ad-dc || true
121 BACKUP_SUFFIX=".orig.$(date +%Y%m%d-%H%M%S)"
123 FILE=/etc/samba/smb.conf
124 test -f ${FILE} || touch ${FILE}
125 mv -f ${FILE} ${FILE}${BACKUP_SUFFIX}
127 samba-tool domain provision \
130 --adminpass=${ADMINPASS} \
132 --function-level=${FUNCTION_LEVEL} \
135 FILE=/etc/resolv.conf
136 test -f ${FILE} || touch ${FILE}
137 mv -f ${FILE} ${FILE}${BACKUP_SUFFIX}
144 sudo sed -i${BACKUP_SUFFIX} -e 's/passwd: .*/passwd: files winbind/g' -e 's/group: .*/group: files winbind/g' /etc/nsswitch.conf
150 Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
152 if Vagrant.has_plugin?("vagrant-cachier")
153 config.cache.scope = :box
156 vms.each do |machine|
157 config.vm.define machine[:hostname] do |node|
158 node.vm.box = machine[:box]
159 node.vm.hostname = machine[:hostname]
160 node.vm.provider :lxc do |lxc|
161 lxc.container_name = machine[:provider][:lxc][:container_name]
163 machine[:networks].each do |net|
164 network_opts.each do |key|
165 if not net[key] == ''
166 lxc.customize "network.#{key}", net[key]
172 #node.vm.synced_folder "shared/", "/shared"
174 node.vm.provision :shell, inline: SCRIPT_INSTALL
175 if machine[:role] == 's4dc'
176 cfg = machine[:config][:s4dc]
177 node.vm.provision :shell do |s|
178 s.inline = SCRIPT_PROVISION
179 s.args = [ cfg[:domain], cfg[:realm], cfg[:adminpass],
180 cfg[:function_level] ]
187 # Provisioning common to all machines: