source: installer/vagrant/Vagrantfile-prod-vbox @ 9215580

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-instalacionwebconsole3
Last change on this file since 9215580 was b1fa023, checked in by Ramón M. Gómez <ramongomez@…>, 7 years ago

#840: Incluir directorios que faltaban en instalación; nueva info de instalación y adaptar algunos ficheros Vagrant para descargar desde Github.

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