source: installer/vagrant/Vagrantfile-1.1.1d-vbox @ 9f4584f

configure-oglivelgromero-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 9f4584f was c28eefa, checked in by Natalia Serrano <natalia.serrano@…>, 19 months ago

Log to syslog in a number of shell scripts

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