source: installer/vagrant/Vagrantfile-main-vbox

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

#1066 Changes devel branch name.

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