source: installer/vagrant/Vagrantfile-1.1.1d-vbox

qndtest
Last change on this file was 2225984, checked in by Irina Gómez <irinagomez@…>, 23 months ago

#1066 Releasing OpenGnsys 1.1.1d

  • Property mode set to 100644
File size: 7.3 KB
Line 
1# Vagrantfile to install OpenGnsys virtual environment (production version) using VirtualBox provider.
2
3VAGRANTFILE_API_VERSION = "2"
4# VM provider: Oracle VM VirtualBox.
5ENV['VAGRANT_DEFAULT_PROVIDER'] = "virtualbox"
6# OpenGnsys version and OGAgent version.
7OGVERSION="1.1.1d"
8# OGAgent version.
9OGAGENTVERSION="1.1.2"
10# Language (accepted values: es_ES, ca_ES, en_GB).
11LANGUAGE = "es_ES"
12ENV['LC_ALL'] = LANGUAGE + ".UTF-8"
13# Number of OpenGnsys clients (accepted values: from 2 to 9).
14NCLIENTS = 4
15# Repository virtual disk: file and size (GB).
16REPODISK = "ogRepo.vdi"
17REPOSIZE = 50
18# Amount of memory for server and clients (MB)
19SERVERMEM = 1024        # Minimum: 512
20CLIENTMEM = 512         # Minimum: 256
21# Prefixes for MAC and IP addresses.
22MACPREFIX = "08:00:27:0E:65"
23NETPREFIX = "192.168.2"
24# OpenGnsys Server IP address.
25SERVERIP = "#{NETPREFIX}.10"
26# Local port to access OpenGnsys Server.
27LOCALWEBPORT = 8443
28
29# OpenGnsys Server provisioning script: prepare repo disk, install OpenGnsys, change default interface, configure DHCP server.
30OGSERVERSCRIPT = <<EOT
31# Exit if OpenGnsys is installed.
32[ -f /opt/opengnsys/doc/VERSION.json ] && echo "Cannot provision, OpenGnsys is already installed." && exit 1
33# Create repository disk using LVM, if necesary.
34if [ -z "$(blkid /dev/mapper/og-images | grep ext4)" ]; then
35    pvcreate /dev/sdb
36    vgcreate og /dev/sdb
37    vgchange -ay
38    lvcreate -ay -n images -l 100%VG og
39    mkfs -t ext4 /dev/mapper/og-images
40    mkdir -p /opt/opengnsys/images
41    echo "/dev/mapper/og-images  /opt/opengnsys/images  ext4  defaults  0  0" >> /etc/fstab
42    mount -a
43fi
44# Install OpenGnsys and change server address.
45if which curl &>/dev/null; then
46    DOWNLOAD="curl -s"
47elif which wget &>/dev/null; then
48    DOWNLOAD="wget -q -O -"
49fi
50BRANCH="opengnsys-#{OGVERSION}"
51$DOWNLOAD "https://raw.githubusercontent.com/opengnsys/OpenGnsys/$BRANCH/installer/opengnsys_installer.sh" | bash || exit $?
52mv /opt/opengnsys/log/bash.log /opt/opengnsys/log/opengnsys_installer.log
53echo y | /opt/opengnsys/bin/setserveraddr $(ip -o link show | tail -1 | cut -d: -f2)
54# Insert DHCP data.
55for ((i=#{NCLIENTS+10}; i>10; i--)); do
56    sed -i "/^}$/ i host pc${i} { hardware ethernet #{MACPREFIX}:${i}; fixed-address #{NETPREFIX}.${i}; }" /etc/dhcp/dhcpd.conf
57done
58service isc-dhcp-server restart
59# Set language.
60export LANG="#{LANGUAGE}.UTF-8"
61echo "LANG=\\\"$LANG\\\"" > /etc/default/locale
62echo "LANG=\\\"$LANG\\\"" >> /etc/environment
63locale-gen --lang #{LANGUAGE}
64sed -i "s/XKBLAYOUT=.*/XKBLAYOUT=\\\"${LANG%_*}\\\"/" /etc/default/keyboard
65dpkg-reconfigure -fnoninteractive console-setup
66# Comment out next lines for automatic data insertion.
67#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"
68#for ((i=11; i<=#{NCLIENTS+10}; i++)); do
69#    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'),"
70#done
71#mysql -u usuog -ppassusuog -D ogAdmBD -e "${SQL%,}"
72#/opt/opengnsys/bin/setclientmode ogLiveAdmin pc11 PERM
73#for ((i=12; i<=#{NCLIENTS+10}; i++)); do
74#    /opt/opengnsys/bin/setclientmode ogLive pc$i PERM
75#done
76echo "Notes:"
77echo "- OpenGnsys Server URL: https://localhost:#{LOCALWEBPORT}/opengnsys/"
78exit 0
79EOT
80
81# Client 1 OS provisioning script.
82MODELSCRIPT = <<EOT
83# Comment out next lines to install and configure OGAgent for Ubuntu.
84#OGAGENTPKG="ogagent_#{OGAGENTVERSION}_all.deb"
85#apt-get update -y
86#apt-get install -y curl
87#curl -ks https://#{SERVERIP}/opengnsys/descargas/$OGAGENTPKG -o /tmp/$OGAGENTPKG
88#if [ -f /tmp/$OGAGENTPKG ]; then
89#    apt-get install -y /tmp/$OGAGENTPKG || exit $?
90#    sed -i "0,/remote=/ s,remote=.*,remote=https://#{SERVERIP}/opengnsys/rest/," /usr/share/OGAgent/cfg/ogagent.cfg
91#    rm -f /tmp/$OGAGENTPKG
92#else
93#    echo "Warning: cannot install OGAgent package $OGAGENTPKG"
94#fi
95# Remove network configuration added by Vagrant.
96sed -i "/enp0s3/ d" /etc/network/interfaces
97echo "Notes:"
98echo "- After now, use VirtualBox GUI to disable network interface 1 and restart this VM."
99# Leave VM halted.
100sleep 2
101poweroff &
102EOT
103
104Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
105
106  # OpenGnsys Server VM definition.
107  config.vm.define "ogAdministrator", primary: true do |og|
108    # Specific VirtualBox configuration.
109    og.vm.provider "virtualbox" do |vb|
110      # VM name, memory and CPUs.
111      vb.name = "ogAdministrator"
112      vb.memory = SERVERMEM
113      vb.cpus = 1
114      # 2nd virtual disk path (current dir on Windows, VM dir on other OSes)
115      if Vagrant::Util::Platform.windows? then
116        second_disk = File.join(".", REPODISK)
117      else
118        line = `VBoxManage list systemproperties`.match("Default machine folder.*")[0]
119        vb_machine_folder = line.split(':')[1].strip()
120        second_disk = File.join(vb_machine_folder, vb.name, REPODISK)
121      end
122      # Create repo virtual disk, if needed.
123      unless File.exist?(second_disk)
124        vb.customize ['createhd', '--filename', second_disk, '--size', REPOSIZE * 1024]
125      end
126      # Attach repo virtual disk.
127      vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', second_disk]
128    end
129    # VM base and host name.
130    og.vm.box = "bento/ubuntu-18.04"
131    og.vm.hostname = "ogAdministrator"
132    # Network configuration: forward web port and attach new interface to VMs private network.
133    og.vm.network "forwarded_port", guest: 443, host: LOCALWEBPORT, host_ip: "127.0.0.1"
134    og.vm.network "private_network", mac: "#{MACPREFIX}10".tr(":",""), ip: "#{SERVERIP}", virtualbox__intnet: true
135    # Comment out to disable synced folder.
136    #og.vm.synced_folder ".", "/vagrant", disabled: true
137    # Launch provisioning script.
138    og.vm.provision "shell", inline: OGSERVERSCRIPT
139  end
140
141  # Client 1 VM definition.
142  config.vm.define "pc11", autostart: false do |v1|
143    v1.vm.box = "bento/ubuntu-18.04"
144    v1.vm.hostname = "pc11"
145    v1.vm.network "private_network", mac: "#{MACPREFIX}11".tr(":",""), type: "dhcp", virtualbox__intnet: true
146    v1.vm.provider "virtualbox" do |vb|
147      vb.name = "pc11"
148      vb.memory = CLIENTMEM
149      vb.cpus = 1
150      vb.customize ['modifyvm', :id, '--boot1', 'net', '--boot2', 'disk']
151    end
152    v1.vm.synced_folder ".", "/vagrant", disabled: true
153    v1.vm.provision "shell", inline: MODELSCRIPT
154  end
155
156  # Clonable clients definition.
157  (2..NCLIENTS).each do |i|
158    config.vm.define "pc#{i+10}", autostart: false do |cl|
159      cl.vm.box = "clink15/pxe"
160      cl.ssh.insert_key = false
161      cl.vm.boot_timeout = 5
162      cl.vm.network "private_network", mac: "#{MACPREFIX}#{i+10}".tr(":",""), type: "dhcp", virtualbox__intnet: true
163      cl.vm.provider "virtualbox" do |vb|
164        vb.name = "pc#{i+10}"
165        vb.memory = CLIENTMEM
166        vb.cpus = 1
167        vb.customize ['modifyvm', :id, '--boot1', 'net', '--boot2', 'disk']
168        vb.customize ["modifyvm", :id, "--nic1", "none"]
169      end
170    end
171  end
172
173end
174
Note: See TracBrowser for help on using the repository browser.