source: installer/vagrant/Vagrantfile-devel-vbox @ 72d19da

918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacion
Last change on this file since 72d19da was ccfd26b, checked in by Ramón M. Gómez <ramongomez@…>, 6 years ago

#739: Vagrant provisioning scripts try to get the name of the internal network interface.

  • Property mode set to 100644
File size: 8.5 KB
Line 
1# Vagrantfile to install OpenGnsys virtual environment (development version) using VirtualBox provider.
2
3VAGRANTFILE_API_VERSION = "2"
4# VM provider: Oracle VM VirtualBox.
5ENV['VAGRANT_DEFAULT_PROVIDER'] = "virtualbox"
6# Language (accepted values: es_ES, ca_ES, en_GB).
7LANGUAGE = "es_ES"
8ENV['LC_ALL'] = LANGUAGE + ".UTF-8"
9# Number of OpenGnsys clients (accepted values: from 2 to 9).
10NCLIENTS = 4
11# Repository virtual disk: file and size (GB).
12REPODISK = "ogRepo.vdi"
13REPOSIZE = 50
14# Amount of memory for server and clients (MB)
15SERVERMEM = 1024        # Minimum: 512
16CLIENTMEM = 512         # Minimum: 256
17# Prefixes for MAC and IP addresses.
18MACPREFIX = "08:00:27:0E:65"
19NETPREFIX = "192.168.2"
20# OpenGnsys Server IP address.
21SERVERIP = "#{NETPREFIX}.10"
22# Local port to access OpenGnsys Server.
23LOCALWEBPORT = 8443
24
25# OpenGnsys Server provisioning script: prepare repo disk, install OpenGnsys, change default interface, configure DHCP server.
26OGSERVERSCRIPT = <<EOT
27# Exit if OpenGnsys is installed.
28[ -f /opt/opengnsys/doc/VERSION.json ] && echo "Cannot provision, OpenGnsys is already installed." && exit 1
29# Create repository disk using LVM, if necesary.
30if [ -z "$(blkid /dev/mapper/og-images | grep ext4)" ]; then
31    pvcreate /dev/sdb
32    vgcreate og /dev/sdb
33    vgchange -ay
34    lvcreate -ay -n images -l 100%VG og
35    mkfs -t ext4 /dev/mapper/og-images
36    mkdir -p /opt/opengnsys/images
37    echo "/dev/mapper/og-images  /opt/opengnsys/images  ext4  defaults  0  0" >> /etc/fstab
38    mount -a
39fi
40# Install OpenGnsys and change server address.
41if which curl &>/dev/null; then
42    DOWNLOAD="curl -s"
43elif which wget &>/dev/null; then
44    DOWNLOAD="wget -q -O -"
45fi
46$DOWNLOAD -s https://raw.githubusercontent.com/opengnsys/OpenGnsys/devel/installer/opengnsys_installer.sh | bash || exit $?
47mv /opt/opengnsys/log/bash.log /opt/opengnsys/log/opengnsys_installer.log
48echo y | /opt/opengnsys/bin/setserveraddr $(ip -o link show | tail -1 | cut -d: -f2)
49# Insert DHCP data.
50for ((i=#{NCLIENTS+10}; i>10; i--)); do
51    sed -i "/^}$/ i host pc${i} { hardware ethernet #{MACPREFIX}:${i}; fixed-address #{NETPREFIX}.${i}; }" /etc/dhcp/dhcpd.conf
52done
53service isc-dhcp-server restart
54# Set language.
55export LANG="#{LANGUAGE}.UTF-8"
56echo "LANG=\\\"$LANG\\\"" > /etc/default/locale
57echo "LANG=\\\"$LANG\\\"" >> /etc/environment
58locale-gen --lang #{LANGUAGE}
59sed -i "s/XKBLAYOUT=.*/XKBLAYOUT=\\\"${LANG%_*}\\\"/" /etc/default/keyboard
60dpkg-reconfigure -fnoninteractive console-setup
61# Comment out next lines for automatic data insertion.
62#SQL="INSERT INTO aulas (nombreaula, idcentro, urlfoto, grupoid, ubicacion, puestos, modomul, ipmul, pormul, velmul, router, netmask, ntp, dns, proxy, modp2p, timep2p) VALUES  ('Aula virtual', 1, 'aula.jpg', 0, 'Despliegue virtual con Vagrant.', 5, 2, '239.194.2.11', 9000, 70, '#{NETPREFIX}.1', '255.255.255.0', '', '', '', 'peer', 30); INSERT INTO ordenadores (nombreordenador, ip, mac, idaula, idrepositorio, idperfilhard, idmenu, idproautoexec, grupoid, router, mascara, arranque, netiface, netdriver, fotoord) VALUES"
63#for ((i=11; i<=#{NCLIENTS+10}; i++)); do
64#    SQL="$SQL ('pc$i', '#{NETPREFIX}.$i', REPLACE('#{MACPREFIX}$i',':',''), 1, 1, 0, 0, 0, 0, '#{NETPREFIX}.1', '255.255.255.0', '00unknown', 'eth0', 'generic', 'fotoordenador.gif'),"
65#done
66#mysql -u usuog -ppassusuog -D ogAdmBD -e "${SQL%,}"
67#/opt/opengnsys/bin/setclientmode ogLiveAdmin pc11 PERM
68#for ((i=12; i<=#{NCLIENTS+10}; i++)); do
69#    /opt/opengnsys/bin/setclientmode ogLive pc$i PERM
70#done
71# Comment out next lines to install new Angular-based web application (on early development).
72#apt-get install -y git nodejs npm
73#ln -fs nodejs /usr/bin/node
74#npm install bower -g
75#svn export https://opengnsys.es/svn/branches/version1.1-tickets/ogWebAdmin-ticket761/admin/WebConsole/angular /opt/opengnsys/www/angular
76#cd /opt/opengnsys/www/angular
77#chown -R vagrant.vagrant .
78#su vagrant -c "bower install -F"
79#sed -i 's!BASE_URL = .*$!BASE_URL = "https://localhost:#{LOCALWEBPORT}/opengnsys";!' ogWebAdmin/assets/js/config.constants.js
80#### TEMPORAL PATCHES
81#su vagrant -c "bower install angular-sanitize -F"
82#su vagrant -c "bower install angular-translate-loader-static-files -F"
83#su vagrant -c "bower install angular-ui-select -F"
84#su vagrant -c "bower install bootstrap -F"
85#su vagrant -c "bower install isteven-angular-multiselect -F"
86#ln -s globunet-util.min.css ogWebAdmin/lib/globunet/dist/css/globunet-util.css
87#cp -a ogWebAdmin/assets/i18n/es.json ogWebAdmin/assets/i18n/en.json
88#sed -i 's/jm.bardallo/usuog/' ogWebAdmin/assets/js/controllers/login.controller.js
89#sed -i "s/DirectoryIndex index.php/DirectoryIndex index.php index.html/" /etc/apache2/sites-enabled/opengnsys.conf
90#service apache2 reload
91echo "Notes:"
92echo "- OpenGnsys Server URL: https://localhost:#{LOCALWEBPORT}/opengnsys/"
93[ -d /opt/opengnsys/www/angular ] && echo "- Angular-based web URL: https://localhost:#{LOCALWEBPORT}/opengnsys/angular/ogWebAdmin/"
94exit 0
95EOT
96
97# Client 1 OS provisioning script.
98OGAGENTPKG = "ogagent_1.1.0_all.deb"
99MODELSCRIPT = <<EOT
100# Comment out next lines to install and configure OGAgent for Ubuntu.
101#apt-get update -y
102#apt-get install -y curl
103#curl -ks https://#{SERVERIP}/opengnsys/descargas/#{OGAGENTPKG} -o /tmp/#{OGAGENTPKG}
104#if [ -f /tmp/#{OGAGENTPKG} ]; then
105#    apt-get install -y /tmp/#{OGAGENTPKG} || exit $?
106#    sed -i "0,/remote=/ s,remote=.*,remote=https://#{SERVERIP}/opengnsys/rest/," /usr/share/OGAgent/cfg/ogagent.cfg
107#    rm -f /tmp/#{OGAGENTPKG}
108#else
109#    echo "Warning: cannot install OGAgent package #{OGAGENTPKG}"
110#fi
111# Remove network configuration added by Vagrant.
112sed -i "/enp0s3/ d" /etc/network/interfaces
113echo "Notes:"
114echo "- After now, use VirtualBox GUI to disable network interface 1 and restart this VM."
115# Leave VM halted.
116sleep 2
117poweroff &
118EOT
119
120Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
121
122  # OpenGnsys Server VM definition.
123  config.vm.define "ogAdministrator", primary: true do |og|
124    # Specific VirtualBox configuration.
125    og.vm.provider "virtualbox" do |vb|
126      # VM name, memory and CPUs.
127      vb.name = "ogAdministrator"
128      vb.memory = SERVERMEM
129      vb.cpus = 1
130      # 2nd virtual disk path (current dir on Windows, VM dir on other OSes)
131      if Vagrant::Util::Platform.windows? then
132        second_disk = File.join(".", REPODISK)
133      else
134        line = `VBoxManage list systemproperties`.match("Default machine folder.*")[0]
135        vb_machine_folder = line.split(':')[1].strip()
136        second_disk = File.join(vb_machine_folder, vb.name, REPODISK)
137      end
138      # Create repo virtual disk, if needed.
139      unless File.exist?(second_disk)
140        vb.customize ['createhd', '--filename', second_disk, '--size', REPOSIZE * 1024]
141      end
142      # Attach repo virtual disk.
143      vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', second_disk]
144    end
145    # VM base and host name.
146    og.vm.box = "bento/ubuntu-16.04"
147    og.vm.hostname = "ogAdministrator"
148    # Network configuration: forward web port and attach new interface to VMs private network.
149    og.vm.network "forwarded_port", guest: 443, host: LOCALWEBPORT, host_ip: "127.0.0.1"
150    og.vm.network "private_network", mac: "#{MACPREFIX}10".tr(":",""), ip: "#{SERVERIP}", virtualbox__intnet: true
151    # Comment out to disable synced folder.
152    #og.vm.synced_folder ".", "/vagrant", disabled: true
153    # Launch provisioning script.
154    og.vm.provision "shell", inline: OGSERVERSCRIPT
155  end
156
157  # Client 1 VM definition.
158  config.vm.define "pc11", autostart: false do |v1|
159    v1.vm.box = "bento/ubuntu-16.04"
160    v1.vm.hostname = "pc11"
161    v1.vm.network "private_network", mac: "#{MACPREFIX}11".tr(":",""), type: "dhcp", virtualbox__intnet: true
162    v1.vm.provider "virtualbox" do |vb|
163      vb.name = "pc11"
164      vb.memory = CLIENTMEM
165      vb.cpus = 1
166      vb.customize ['modifyvm', :id, '--boot1', 'net', '--boot2', 'disk']
167    end
168    v1.vm.synced_folder ".", "/vagrant", disabled: true
169    v1.vm.provision "shell", inline: MODELSCRIPT
170  end
171
172  # Clonable clients definition.
173  (2..NCLIENTS).each do |i|
174    config.vm.define "pc#{i+10}", autostart: false do |cl|
175      cl.vm.box = "clink15/pxe"
176      cl.ssh.insert_key = false
177      cl.vm.boot_timeout = 5
178      cl.vm.network "private_network", mac: "#{MACPREFIX}#{i+10}".tr(":",""), type: "dhcp", virtualbox__intnet: true
179      cl.vm.provider "virtualbox" do |vb|
180        vb.name = "pc#{i+10}"
181        vb.memory = CLIENTMEM
182        vb.cpus = 1
183        vb.customize ['modifyvm', :id, '--boot1', 'net', '--boot2', 'disk']
184        vb.customize ["modifyvm", :id, "--nic1", "none"]
185      end
186    end
187  end
188
189end
190
Note: See TracBrowser for help on using the repository browser.