source: installer/vagrant/Vagrantfile-devel-vbox @ 560358b

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-instalacion
Last change on this file since 560358b was 4220550, checked in by Ramón M. Gómez <ramongomez@…>, 6 years ago

#914: Remove obsolete code from Vagrant file for development environment.

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