source: installer/vagrant/Vagrantfile-1.1.1d-vbox @ 5e2f844

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 5e2f844 was 11fbd77, checked in by Natalia Serrano <natalia.serrano@…>, 17 months ago

Install git upon OG installation. Update GIT_REPO

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