source: installer/vagrant/Vagrantfile-trunk-vbox @ 53c03ca

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 53c03ca was ccec614, checked in by ramon <ramongomez@…>, 8 years ago

#739: Retocar fichero Vagrant para permitir reaprovisionamiento de servidor y solucionar problemas que pueden producirse durante una instalación previa de paquetes.

git-svn-id: https://opengnsys.es/svn/branches/version1.1@5279 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100644
File size: 6.3 KB
Line 
1# Vagrantfile to install OpenGnsys Trunk virtual environment 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# Clients MAC address prefix.
18MACPREFIX = "08:00:27:0E:65:"
19NETPREFIX = "192.168.2."
20# Local port to access OpenGnsys Server.
21LOCALWEBPORT = 8443
22
23# OpenGnsys Server provisioning script: prepare repo disk, install OpenGnsys, change default interface, configure DHCP server.
24OGSERVERSCRIPT = <<EOT
25# Exit if OpenGnsys is installed.
26[ -f /opt/opengnsys/doc/VERSION.txt ] && echo "Cannot provision, OpenGnsys is already installed." && exit 1
27# Mount repository disk, if necesary.
28if [ -n "$(blkid /dev/sdb1 | grep ext4)" ]; then
29    echo -e "o\nn\np\n\n\n\nw" | fdisk /dev/sdb
30    mkfs -t ext4 /dev/sdb1
31    mkdir -p /opt/opengnsys/images
32    echo "/dev/sdb1  /opt/opengnsys/images  ext4  defaults  0  0" >> /etc/fstab
33    mount -a
34fi
35# Install OpenGnsys and change server address.
36wget -q http://opengnsys.es/svn/trunk/installer/opengnsys_installer.sh -O - | bash || exit $?
37mv /opt/opengnsys/log/bash.log /opt/opengnsys/log/opengnsys_installer.log
38echo y | sudo /opt/opengnsys/bin/setserveraddr eth1
39# Insert DHCP data.
40for ((i=#{NCLIENTS}; i>0; i--)); do
41    sed -i "/^}$/ i host ogClient0${i} { hardware ethernet #{MACPREFIX}0${i}; fixed-address #{NETPREFIX}1${i}; }" /etc/dhcp/dhcpd.conf
42done
43service isc-dhcp-server restart
44# Set language.
45export LANG="#{LANGUAGE}.UTF-8"
46echo "LANG=\"$LANG\"" > /etc/default/locale
47echo "LANG=\"$LANG\"" >> /etc/environment
48locale-gen --lang #{LANGUAGE}
49sed -i "s/XKBLAYOUT=.*/XKBLAYOUT=\"${LANG%_*}\"/" /etc/default/keyboard
50dpkg-reconfigure -fnoninteractive console-setup
51# Comment out next lines for automatic data insertion.
52#SQL="INSERT INTO aulas (nombreaula, idcentro, urlfoto, grupoid, ubicacion, puestos, modomul, ipmul, pormul, velmul, router, netmask, 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"
53#for ((i=1; i<=#{NCLIENTS}; i++)); do
54#    SQL="$SQL ('ogClient0$i', '#{NETPREFIX}1$i', REPLACE('#{MACPREFIX}0$i',':',''), 1, 1, 0, 0, 0, 0, '#{NETPREFIX}1', '255.255.255.0', '00unknown', 'eth0', 'generic', 'fotoordenador.gif'),"
55#done
56#mysql -u usuog -ppassusuog -D ogAdmBD -e "${SQL%,}"
57#if ! grep -q "1\.0" /opt/opengnsys/doc/VERSION.txt; then AUX=1; fi
58#/opt/opengnsys/bin/setclientmode ogAdmin ogClient01 $AUX
59#for ((i=2; i<=#{NCLIENTS}; i++)); do
60#    /opt/opengnsys/bin/setclientmode ogClient ogClient0$i $AUX
61#done
62echo "New OpenGnsys local URL: https://localhost:#{LOCALWEBPORT}/opengnsys/"
63EOT
64
65# Client 1 OS provisioning script.
66MODELSCRIPT = <<EOT
67# Remove network configuration added by Vagrant.
68sed -i "/VAGRANT/,$ d" /etc/network/interfaces
69echo "After now, use VirtualBox GUI to disable network interface 1 and work with this VM."
70# Leave VM halted.
71sleep 2
72poweroff &
73EOT
74
75Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
76
77  # OpenGnsys Server VM definition.
78  config.vm.define "ogAdministrator", primary: true do |og|
79    # Specific VirtualBox configuration.
80    og.vm.provider "virtualbox" do |vb|
81      # VM name, memory and CPUs.
82      vb.name = "ogAdministrator"
83      vb.memory = SERVERMEM
84      vb.cpus = 1
85      # 2nd virtual disk path (current dir on Windows, VM dir on other OSes)
86      if Vagrant::Util::Platform.windows? then
87        second_disk = File.join(".", REPODISK)
88      else
89        line = `VBoxManage list systemproperties`.match("Default machine folder.*")[0]
90        vb_machine_folder = line.split(':')[1].strip()
91        second_disk = File.join(vb_machine_folder, vb.name, REPODISK)
92      end
93      # Create repo virtual disk, if needed.
94      unless File.exist?(second_disk)
95        vb.customize ['createhd', '--filename', second_disk, '--size', REPOSIZE * 1024]
96      end
97      # Attach repo virtual disk.
98      vb.customize ['storageattach', :id, '--storagectl', 'SATAController', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', second_disk]
99    end
100    # VM base and host name.
101    og.vm.box = "ubuntu/trusty64"
102    og.vm.hostname = "ogAdministrator"
103    # Network configuration: forward web port and attach new interface to VMs private network.
104    og.vm.network "forwarded_port", guest: 443, host: LOCALWEBPORT, host_ip: "127.0.0.1"
105    og.vm.network "private_network", ip: "#{NETPREFIX}10", virtualbox__intnet: true
106    # Comment out to disable synced folder.
107    #og.vm.synced_folder ".", "/vagrant", disabled: true
108    # Launch provisioning script.
109    og.vm.provision "shell", inline: OGSERVERSCRIPT
110  end
111
112  # Client 1 VM definition.
113  config.vm.define "ogClient01", autostart: false do |v1|
114    v1.vm.box = "ubuntu/trusty64"
115    v1.vm.hostname = "ogClient01"
116    v1.vm.network "private_network", mac: "#{MACPREFIX}01".tr(":",""), type: "dhcp", virtualbox__intnet: true
117    v1.vm.provider "virtualbox" do |vb|
118      vb.name = "ogClient01"
119      vb.memory = CLIENTMEM
120      vb.cpus = 1
121      vb.customize ['modifyvm', :id, '--boot1', 'net', '--boot2', 'disk']
122    end
123    v1.vm.synced_folder ".", "/vagrant", disabled: true
124    v1.vm.provision "shell", inline: MODELSCRIPT
125  end
126
127  # Clonable clients definition.
128  (2..NCLIENTS).each do |i|
129    config.vm.define "ogClient0#{i}", autostart: false do |cl|
130      cl.vm.box = "clink15/pxe"
131      cl.ssh.insert_key = false
132      cl.vm.boot_timeout = 5
133      cl.vm.network "private_network", mac: "#{MACPREFIX}".tr(":","") + "%02d" % "#{i}", type: "dhcp", virtualbox__intnet: true
134      cl.vm.provider "virtualbox" do |vb|
135        vb.name = "ogClient0#{i}"
136        vb.memory = CLIENTMEM
137        vb.cpus = 1
138        vb.customize ['modifyvm', :id, '--boot1', 'net', '--boot2', 'disk']
139        vb.customize ["modifyvm", :id, "--nic1", "none"]
140      end
141    end
142  end
143
144end
145
Note: See TracBrowser for help on using the repository browser.