source: installer/vagrant/Vagrantfile-devel-vbox @ 9215580

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-instalacionwebconsole3
Last change on this file since 9215580 was bf4b65c, checked in by Ramón M. Gómez <ramongomez@…>, 7 years ago

#843: Web interface uses new version file and correcting some errata.

  • Property mode set to 100644
File size: 8.3 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.
41curl -s https://raw.githubusercontent.com/opengnsys/OpenGnsys/devel/installer/opengnsys_installer.sh | bash || exit $?
42mv /opt/opengnsys/log/bash.log /opt/opengnsys/log/opengnsys_installer.log
43echo y | /opt/opengnsys/bin/setserveraddr enp0s8
44# Insert DHCP data.
45for ((i=#{NCLIENTS+10}; i>10; i--)); do
46    sed -i "/^}$/ i host pc${i} { hardware ethernet #{MACPREFIX}:${i}; fixed-address #{NETPREFIX}.${i}; }" /etc/dhcp/dhcpd.conf
47done
48service isc-dhcp-server restart
49# Set language.
50export LANG="#{LANGUAGE}.UTF-8"
51echo "LANG=\"$LANG\"" > /etc/default/locale
52echo "LANG=\"$LANG\"" >> /etc/environment
53locale-gen --lang #{LANGUAGE}
54sed -i "s/XKBLAYOUT=.*/XKBLAYOUT=\"${LANG%_*}\"/" /etc/default/keyboard
55dpkg-reconfigure -fnoninteractive console-setup
56# Comment out next lines for automatic data insertion.
57#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"
58#for ((i=11; i<=#{NCLIENTS+10}; i++)); do
59#    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'),"
60#done
61#mysql -u usuog -ppassusuog -D ogAdmBD -e "${SQL%,}"
62#/opt/opengnsys/bin/setclientmode ogLiveAdmin pc11 PERM
63#for ((i=12; i<=#{NCLIENTS+10}; i++)); do
64#    /opt/opengnsys/bin/setclientmode ogLive pc$i PERM
65#done
66# Comment out next lines to install new Angular-based web application (on early development).
67#apt-get install -y git nodejs npm
68#ln -fs nodejs /usr/bin/node
69#npm install bower -g
70#svn export https://opengnsys.es/svn/branches/version1.1-tickets/ogWebAdmin-ticket761/admin/WebConsole/angular /opt/opengnsys/www/angular
71#cd /opt/opengnsys/www/angular
72#chown -R vagrant.vagrant .
73#su vagrant -c "bower install -F"
74#sed -i 's!BASE_URL = .*$!BASE_URL = "https://localhost:#{LOCALWEBPORT}/opengnsys";!' ogWebAdmin/assets/js/config.constants.js
75#### TEMPORAL PATCHES
76#su vagrant -c "bower install angular-sanitize -F"
77#su vagrant -c "bower install angular-translate-loader-static-files -F"
78#su vagrant -c "bower install angular-ui-select -F"
79#su vagrant -c "bower install bootstrap -F"
80#su vagrant -c "bower install isteven-angular-multiselect -F"
81#ln -s globunet-util.min.css ogWebAdmin/lib/globunet/dist/css/globunet-util.css
82#cp -a ogWebAdmin/assets/i18n/es.json ogWebAdmin/assets/i18n/en.json
83#sed -i 's/jm.bardallo/usuog/' ogWebAdmin/assets/js/controllers/login.controller.js
84#sed -i "s/DirectoryIndex index.php/DirectoryIndex index.php index.html/" /etc/apache2/sites-enabled/opengnsys.conf
85#service apache2 reload
86echo "Notes:"
87echo "- OpenGnsys Server URL: https://localhost:#{LOCALWEBPORT}/opengnsys/"
88[ -d /opt/opengnsys/www/angular ] && echo "- Angular-based web URL: https://localhost:#{LOCALWEBPORT}/opengnsys/angular/ogWebAdmin/"
89exit 0
90EOT
91
92# Client 1 OS provisioning script.
93OGAGENTPKG = "ogagent_1.1.0_all.deb"
94MODELSCRIPT = <<EOT
95# Comment out next lines to install and configure OGAgent for Ubuntu.
96#apt-get update -y
97#curl -ks https://#{SERVERIP}/opengnsys/descargas/#{OGAGENTPKG} -o #{OGAGENTPKG}
98#if [ -f #{OGAGENTPKG} ]; then
99#    dpkg -i #{OGAGENTPKG}
100#    apt-get install -fy || exit $?
101#    sed -i "0,/remote=/ s,remote=.*,remote=https://#{SERVERIP}/opengnsys/rest/," /usr/share/OGAgent/cfg/ogagent.cfg
102#    rm -f #{OGAGENTPKG}
103#else
104#    echo "Warning: cannot install OGAgent package #{OGAGENTPKG}"
105#fi
106# Remove network configuration added by Vagrant.
107sed -i "/enp0s3/ d" /etc/network/interfaces
108echo "Notes:"
109echo "- After now, use VirtualBox GUI to disable network interface 1 and restart this VM."
110# Leave VM halted.
111sleep 2
112poweroff &
113EOT
114
115Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
116
117  # OpenGnsys Server VM definition.
118  config.vm.define "ogAdministrator", primary: true do |og|
119    # Specific VirtualBox configuration.
120    og.vm.provider "virtualbox" do |vb|
121      # VM name, memory and CPUs.
122      vb.name = "ogAdministrator"
123      vb.memory = SERVERMEM
124      vb.cpus = 1
125      # 2nd virtual disk path (current dir on Windows, VM dir on other OSes)
126      if Vagrant::Util::Platform.windows? then
127        second_disk = File.join(".", REPODISK)
128      else
129        line = `VBoxManage list systemproperties`.match("Default machine folder.*")[0]
130        vb_machine_folder = line.split(':')[1].strip()
131        second_disk = File.join(vb_machine_folder, vb.name, REPODISK)
132      end
133      # Create repo virtual disk, if needed.
134      unless File.exist?(second_disk)
135        vb.customize ['createhd', '--filename', second_disk, '--size', REPOSIZE * 1024]
136      end
137      # Attach repo virtual disk.
138      vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', second_disk]
139    end
140    # VM base and host name.
141    og.vm.box = "bento/ubuntu-16.04"
142    og.vm.hostname = "ogAdministrator"
143    # Network configuration: forward web port and attach new interface to VMs private network.
144    og.vm.network "forwarded_port", guest: 443, host: LOCALWEBPORT, host_ip: "127.0.0.1"
145    og.vm.network "private_network", mac: "#{MACPREFIX}10".tr(":",""), ip: "#{SERVERIP}", virtualbox__intnet: true
146    # Comment out to disable synced folder.
147    #og.vm.synced_folder ".", "/vagrant", disabled: true
148    # Launch provisioning script.
149    og.vm.provision "shell", inline: OGSERVERSCRIPT
150  end
151
152  # Client 1 VM definition.
153  config.vm.define "pc11", autostart: false do |v1|
154    v1.vm.box = "bento/ubuntu-16.04"
155    v1.vm.hostname = "pc11"
156    v1.vm.network "private_network", mac: "#{MACPREFIX}11".tr(":",""), type: "dhcp", virtualbox__intnet: true
157    v1.vm.provider "virtualbox" do |vb|
158      vb.name = "pc11"
159      vb.memory = CLIENTMEM
160      vb.cpus = 1
161      vb.customize ['modifyvm', :id, '--boot1', 'net', '--boot2', 'disk']
162    end
163    v1.vm.synced_folder ".", "/vagrant", disabled: true
164    v1.vm.provision "shell", inline: MODELSCRIPT
165  end
166
167  # Clonable clients definition.
168  (2..NCLIENTS).each do |i|
169    config.vm.define "pc#{i+10}", autostart: false do |cl|
170      cl.vm.box = "clink15/pxe"
171      cl.ssh.insert_key = false
172      cl.vm.boot_timeout = 5
173      cl.vm.network "private_network", mac: "#{MACPREFIX}#{i+10}".tr(":",""), type: "dhcp", virtualbox__intnet: true
174      cl.vm.provider "virtualbox" do |vb|
175        vb.name = "pc#{i+10}"
176        vb.memory = CLIENTMEM
177        vb.cpus = 1
178        vb.customize ['modifyvm', :id, '--boot1', 'net', '--boot2', 'disk']
179        vb.customize ["modifyvm", :id, "--nic1", "none"]
180      end
181    end
182  end
183
184end
185
Note: See TracBrowser for help on using the repository browser.