source: installer/vagrant/Vagrantfile-esxi @ fee080a

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 fee080a was 692e9417, checked in by Nicolas Arenas <nicolas.arenas@…>, 20 months ago

Test for using ask pass

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