source: installer/vagrant/Vagrantfile-esxi @ 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 915580e, checked in by Nicolas Arenas <nicolas.arenas@…>, 19 months ago

Merge branch 'terraform-clients'

  • Property mode set to 100644
File size: 6.3 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'] = "vmware_esxi"
6# OpenGnsys version and OGAgent version.
7OGVERSION=ENV['OGVERSION'] || "test"
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 = ENV['NUMBER_OF_CLIENTS']|| 4
15NCLIENTS = NCLIENTS.to_i
16# Repository virtual disk: file and size (GB).
17REPODISK = "ogRepo.vdi"
18REPOSIZE = 50
19# Amount of memory for server and clients (MB)
20SERVERMEM = 2048        # Minimum: 512
21CLIENTMEM = 512         # Minimum: 256
22# Prefixes for MAC and IP addresses.
23MACPREFIX = ENV['OGN_MAC_PREFIX'] || '00:50:56:aa:aa'
24NETPREFIX = ENV['OGN_NET_PREFIX'] || "192.168.2"
25DHCPNET   = ENV['DHCPNET'] || "192.168.2.0"
26# OpenGnsys Server IP address.
27SERVERIP = "#{NETPREFIX}.10"
28# Local port to access OpenGnsys Server.
29LOCALWEBPORT = 8443
30# ESXI Password
31ESXIPASSWORD = ENV['ESXI_PASSWORD'] || 'prompt:'
32
33#Gitea credentials
34GITEA_TOKEN = ENV['GITEA_TOKEN']
35GITEA_USER = ENV['GITEA_USER'] || 'unizar'
36SSH_GIT_KEY_PASS = ENV['SSH_GIT_KEY_PASS'] || ''
37
38# OpenGnsys Server provisioning script: prepare repo disk, install OpenGnsys, change default interface, configure DHCP server.
39OGSERVERSCRIPT = <<EOT
40
41# Fix problem with gitea host
42
43grep -q '^150\.214\.58\.246' /etc/hosts || echo "150.214.58.246 ognproject.evlt.uma.es" >> /etc/hosts
44
45# Fix ssh
46mkdir -p /root/.ssh/
47cp /vagrant/config/id_rsa /root/.ssh/id_rsa
48chown root:root /root/.ssh/id_rsa
49chmod 0400 /root/.ssh/id_rsa
50cp /vagrant/config/ssh_config /root/.ssh/config
51chown root:root /root/.ssh/config
52chmod 0400 /root/.ssh/config
53cp /vagrant/config/ask_pass.sh /root/ask_pass.sh
54chmod 755 /root/ask_pass.sh
55
56# Sets ssh agent to work with git
57eval `ssh-agent`
58export DISPLAY=:0
59export SSH_ASKPASS=/root/ask_pass.sh
60ssh-add /root/.ssh/id_rsa <<< $SSH_GIT_KEY_PASS
61
62
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
71# Exit if OpenGnsys is installed.
72[ -f /opt/opengnsys/doc/VERSION.json ] && echo "Cannot provision, OpenGnsys is already installed." && exit 1
73
74# Create repo disk
75if [ -z "$(blkid /dev/mapper/og-images | grep ext4)" ]; then
76    pvcreate /dev/sdb
77    vgcreate og /dev/sdb
78    vgchange -ay
79    lvcreate -ay -n images -l 100%VG og
80    mkfs -t ext4 /dev/mapper/og-images
81    mkdir -p /opt/opengnsys/images
82    echo "/dev/mapper/og-images  /opt/opengnsys/images  ext4  defaults  0  0" >> /etc/fstab
83    mount -a
84fi
85
86# Configure eth1 iface
87if [ -f /etc/netplan/01-eth1.yaml ]; then
88    echo "Network configured Skipping"
89else
90    echo "Configuring Network"
91    sed -i "s/##ADDRESS##/${NETPREFIX}.1/g" /tmp/01-eth1.yaml
92    mv /tmp/01-eth1.yaml /etc/netplan
93    chown root:root /etc/netplan/01-eth1.yaml
94    netplan apply
95    sleep 1
96fi
97
98
99# Download installer
100BRANCH="$OGVERSION"
101
102curl --show-error --fail -k -L -o opengnsys_installer_devel_esxi.sh https://$GITEA_USER:$GITEA_TOKEN@ognproject.evlt.uma.es/gitea/unizar/opengnsys/raw/branch/${BRANCH}/installer/opengnsys_installer_devel_esxi.sh
103chmod 755 opengnsys_installer_devel_esxi.sh && ./opengnsys_installer_devel_esxi.sh $BRANCH
104mv /opt/opengnsys/log/bash.log /opt/opengnsys/log/opengnsys_installer.log
105
106
107echo y | /opt/opengnsys/bin/setserveraddr $(ip -o link show | tail -1 | cut -d: -f2)
108
109# Insert DHCP data.
110for ((i=#{NCLIENTS+10}; i>10; i--)); do
111    sed -i "/^}$/ i host pc${i} { hardware ethernet #{MACPREFIX}:${i}; fixed-address #{NETPREFIX}.${i}; }" /etc/dhcp/dhcpd.conf
112done
113service isc-dhcp-server restart
114
115# Comment out next lines for automatic data insertion.
116SQL="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"
117for ((i=11; i<=#{NCLIENTS+10}; i++)); do
118    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'),"
119done
120mysql -u usuog -ppassusuog -D ogAdmBD -e "${SQL%,}"
121/opt/opengnsys/bin/setclientmode ogLiveAdmin pc11 PERM
122for ((i=12; i<=#{NCLIENTS+10}; i++)); do
123    /opt/opengnsys/bin/setclientmode ogLive pc$i PERM
124done
125echo "Notes:"
126echo "- OpenGnsys Server URL: https://localhost:${LOCALWEBPORT}/opengnsys/"
127exit 0
128EOT
129
130
131Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
132  # OpenGnsys Server VM definition.
133  config.vm.define "ogAdministrator-#{OGVERSION}", primary: true do |og|
134    # Specific VirtualBox configuration.
135    og.vm.provider :vmware_esxi do |esxi|
136      # VM name, memory and CPUs.
137      esxi.guest_name = "ogAdministrator-#{OGVERSION}"
138      esxi.guest_memsize = SERVERMEM
139      esxi.esxi_username = 'root'
140      esxi.esxi_password = ESXIPASSWORD
141      esxi.esxi_hostname = 'esxi-jenkins.evlt.uma.es'
142      esxi.clone_from_vm = 'Ubuntu-18-template-image'
143      esxi.esxi_resource_pool = "/"
144      esxi.local_allow_overwrite = 'True'
145      esxi.guest_custom_vmx_settings = [['monitor.allowLegacyCPU', 'TRUE']]
146      esxi.guest_storage = [ 10 ]
147      esxi.esxi_virtual_network = [ 'vLan_742', OGVERSION  ]
148      esxi.guest_mac_address = [ "#{MACPREFIX}:00", "#{MACPREFIX}:01" ]
149      esxi.guest_nic_type = 'e1000'
150    end
151    # VM base and host name.
152    og.vm.box = "esxi_clone/dummy"
153    og.vm.hostname = "ogAdministrator-#{OGVERSION}"
154    # Launch provisioning script.
155    og.vm.provision "file", source: "config/01-eth1.yaml" , destination: "/tmp/"
156    og.vm.provision "shell", inline: OGSERVERSCRIPT , env: {"NETPREFIX" => NETPREFIX , "OGVERSION" => OGVERSION , "GITEA_TOKEN" => GITEA_TOKEN , "GITEA_USER" => GITEA_USER , "DHCPNET" => DHCPNET , "SSH_GIT_KEY_PASS" => SSH_GIT_KEY_PASS }
157  end
158
159end
160
161
162
163
Note: See TracBrowser for help on using the repository browser.