source: installer/vagrant/Vagrantfile-esxi @ aaa63f4

configure-oglivelgromero-new-oglivemainmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineoglive-ipv6test-python-scriptsticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacion
Last change on this file since aaa63f4 was aaa63f4, checked in by Natalia Serrano <natalia.serrano@…>, 11 months ago

refs #491 curl can now be more verbose, also retry curls

  • Property mode set to 100644
File size: 10.6 KB
RevLine 
[3a0f599]1VAGRANTFILE_API_VERSION = "2"
2ENV['VAGRANT_DEFAULT_PROVIDER'] = "vmware_esxi"
[bc84890]3
[85df22be]4BRANCH=ENV['BRANCH'] || "main"
5BRANCH_EXTRA=ENV['BRANCH_EXTRA'] || BRANCH
[bc84890]6
[3a0f599]7OGAGENTVERSION="1.1.2"
[bc84890]8
[3a0f599]9LANGUAGE = "es_ES"
10ENV['LC_ALL'] = LANGUAGE + ".UTF-8"
[bc84890]11
[a8044f7]12NCLIENTS = ENV['NUMBER_OF_CLIENTS']|| 4
[915580e]13NCLIENTS = NCLIENTS.to_i
[bc84890]14
15#REPODISK = "ogRepo.vdi"
16#REPOSIZE = 50
17
[3a0f599]18SERVERMEM = 2048        # Minimum: 512
19CLIENTMEM = 512         # Minimum: 256
[bc84890]20
[0fe1fb95]21MACPREFIX = ENV['OGN_MAC_PREFIX'] || '00:50:56:aa:aa'
[6a65c2d]22NETPREFIX = ENV['OGN_NET_PREFIX'] || "192.168.2"
[f43bbbd]23DHCPNET   = ENV['DHCPNET'] || "192.168.2.0"
[bc84890]24
[3a0f599]25SERVERIP = "#{NETPREFIX}.10"
[bc84890]26
[3a0f599]27LOCALWEBPORT = 8443
[bc84890]28
[1f22729]29ESXIPASSWORD = ENV['ESXI_PASSWORD'] || 'prompt:'
[3a0f599]30
[c5afb54]31GITEA_TOKEN = ENV['GITEA_TOKEN']
32GITEA_USER = ENV['GITEA_USER'] || 'unizar'
[bf3f1ed]33SSH_GIT_KEY_PASS = ENV['SSH_GIT_KEY_PASS'] || ''
[c5afb54]34
[4fa8ce3]35
36OGLOGSCRIPT = <<EOT
37echo in oglog script
[a984630]38echo -n 'hostname: '; hostname -f
39echo env vars beginning with OG:
[c3e28cfe]40env |grep OG
[a984630]41ip address show eth0
[4fa8ce3]42EOT
43
44
[3a0f599]45OGSERVERSCRIPT = <<EOT
[6a830177]46echo -n 'hostname: '; hostname -f
47echo env vars beginning with OG:
48env |grep OG
49ip address show eth0
50
[a8044f7]51# Fix problem with gitea host
52grep -q '^150\.214\.58\.246' /etc/hosts || echo "150.214.58.246 ognproject.evlt.uma.es" >> /etc/hosts
[c0b4f96]53
[85df22be]54echo Setting up SSH config and agent
[c9497e6]55mkdir -p /root/.ssh/
56cp /vagrant/config/id_rsa /root/.ssh/id_rsa
57chown root:root /root/.ssh/id_rsa
[a8044f7]58chmod 0400 /root/.ssh/id_rsa
[c9497e6]59cp /vagrant/config/ssh_config /root/.ssh/config
60chown root:root /root/.ssh/config
61chmod 0400 /root/.ssh/config
[a8044f7]62cp /vagrant/config/ask_pass.sh /root/ask_pass.sh
63chmod 755 /root/ask_pass.sh
[692e9417]64
[a8044f7]65eval `ssh-agent`
66export DISPLAY=:0
[692e9417]67export SSH_ASKPASS=/root/ask_pass.sh
[bf3f1ed]68ssh-add /root/.ssh/id_rsa <<< $SSH_GIT_KEY_PASS
[692e9417]69
[787ba5b]70
[85df22be]71echo Setting up language and locales
[c9497e6]72export LANG="#{LANGUAGE}.UTF-8"
73echo "LANG=\\\"$LANG\\\"" > /etc/default/locale
74echo "LANG=\\\"$LANG\\\"" >> /etc/environment
75locale-gen --lang #{LANGUAGE}
76sed -i "s/XKBLAYOUT=.*/XKBLAYOUT=\\\"${LANG%_*}\\\"/" /etc/default/keyboard
77dpkg-reconfigure -fnoninteractive console-setup
[787ba5b]78
[85df22be]79
[3a0f599]80# Exit if OpenGnsys is installed.
[c9497e6]81[ -f /opt/opengnsys/doc/VERSION.json ] && echo "Cannot provision, OpenGnsys is already installed." && exit 1
82
[85df22be]83
84echo Creating a repository disk
[c9497e6]85if [ -z "$(blkid /dev/mapper/og-images | grep ext4)" ]; then
86    pvcreate /dev/sdb
87    vgcreate og /dev/sdb
88    vgchange -ay
89    lvcreate -ay -n images -l 100%VG og
90    mkfs -t ext4 /dev/mapper/og-images
91    mkdir -p /opt/opengnsys/images
92    echo "/dev/mapper/og-images  /opt/opengnsys/images  ext4  defaults  0  0" >> /etc/fstab
93    mount -a
94fi
95
[85df22be]96
[c9497e6]97if [ -f /etc/netplan/01-eth1.yaml ]; then
[85df22be]98    echo "Network configured, skipping"
[c9497e6]99else
[85df22be]100    echo "Configuring eth1"
[c9497e6]101    sed -i "s/##ADDRESS##/${NETPREFIX}.1/g" /tmp/01-eth1.yaml
102    mv /tmp/01-eth1.yaml /etc/netplan
103    chown root:root /etc/netplan/01-eth1.yaml
104    netplan apply
105    sleep 1
106fi
[787ba5b]107
[726f7c0]108
[a8044f7]109# Download installer
[85df22be]110echo Downloading https://ognproject.evlt.uma.es/gitea/opengnsys/opengnsys/raw/branch/${BRANCH}/installer/opengnsys_installer_devel_esxi.sh
[aaa63f4]111curl --retry 5 --stderr - --fail --insecure --location --output opengnsys_installer_devel_esxi.sh https://$GITEA_USER:$GITEA_TOKEN@ognproject.evlt.uma.es/gitea/opengnsys/opengnsys/raw/branch/${BRANCH}/installer/opengnsys_installer_devel_esxi.sh
[6a830177]112chmod 755 opengnsys_installer_devel_esxi.sh && ./opengnsys_installer_devel_esxi.sh $BRANCH
[e202670]113
[6a830177]114[ -e /opt/opengnsys/log/bash.log ] && mv /opt/opengnsys/log/bash.log /opt/opengnsys/log/opengnsys_installer.log
[6b2b601]115
[6a830177]116echo y | /opt/opengnsys/bin/setserveraddr $(ip -o link show | tail -1 | cut -d: -f2)
[c9497e6]117
[3a0f599]118# Insert DHCP data.
[6a830177]119sed -i "/^}$/ i host modelo { hardware ethernet #{MACPREFIX}:FF; fixed-address #{NETPREFIX}.199; }" /etc/dhcp/dhcpd.conf
120for ((i=#{NCLIENTS+10}; i>10; i--)); do
121    sed -i "/^}$/ i host pc${i} { hardware ethernet #{MACPREFIX}:${i}; fixed-address #{NETPREFIX}.${i}; }" /etc/dhcp/dhcpd.conf
122done
123service isc-dhcp-server restart
[2e6fcee]124
125#echo Creating an aula and some clients
[6a830177]126SQL="INSERT INTO aulas (nombreaula, idcentro, urlfoto, grupoid, ubicacion, puestos, modomul, ipmul, pormul, velmul, router, netmask, ntp, dns, proxy, modp2p, timep2p)"\
127"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); "\
128"INSERT INTO ordenadores (nombreordenador, ip, mac, idaula, idrepositorio, idperfilhard, idmenu, idproautoexec, grupoid, router, mascara, arranque, netiface, netdriver, fotoord) VALUES "\
129"('modelo', '#{NETPREFIX}.199', REPLACE('#{MACPREFIX}FF',':',''), 1, 1, 0, 0, 0, 0, '#{NETPREFIX}.1', '255.255.255.0', '00unknown', 'eth0', 'generic', 'fotoordenador.gif'),"
130for ((i=11; i<=#{NCLIENTS+10}; i++)); do
131    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'),"
132done
133mysql -u usuog -ppassusuog -D ogAdmBD -e "${SQL%,}"
134/opt/opengnsys/bin/setclientmode ogLiveAdmin modelo PERM
135/opt/opengnsys/bin/setclientmode ogLiveAdmin pc11 PERM
136for ((i=12; i<=#{NCLIENTS+10}; i++)); do
137    /opt/opengnsys/bin/setclientmode ogLive pc$i PERM
138done
[85df22be]139
[3a0f599]140echo "Notes:"
[6b2b601]141echo "- OpenGnsys Server URL: https://localhost:${LOCALWEBPORT}/opengnsys/"
[3a0f599]142exit 0
143EOT
144
[0c52391]145
[4f70c64]146OGDHCPSCRIPT = <<EOT
147echo in ogdhcp script
[a984630]148echo -n 'hostname: '; hostname -f
149echo env vars beginning with OG:
[c3e28cfe]150env |grep OG
[a984630]151ip address show eth0
[7073c13]152EOT
153
[3a0f599]154
[4f70c64]155OGBOOTSCRIPT = <<EOT
156echo in ogboot script
[a984630]157echo -n 'hostname: '; hostname -f
158echo env vars beginning with OG:
[c3e28cfe]159env |grep OG
[a984630]160ip address show eth0
[6a830177]161echo "OGBOOT_BRANCH ($OGBOOT_BRANCH)"
[4f70c64]162EOT
[84092f8]163
[bc84890]164
[4f70c64]165OGREPOSCRIPT = <<EOT
166echo in ogrepo script
[a984630]167echo -n 'hostname: '; hostname -f
168echo env vars beginning with OG:
[c3e28cfe]169env |grep OG
[a984630]170ip address show eth0
[4f70c64]171EOT
[bc84890]172
[84092f8]173
[4f70c64]174Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
[ea215a9]175    require 'pp'
[86d3587]176
177    def do_debug(msg)
178        if ENV.has_key?("DEBUG_VAGRANT") and ENV["DEBUG_VAGRANT"] == "true" then
[9ffa6b4]179            if msg.class == Array then
[c3e28cfe]180                #PP.pp(msg, STDERR)        ## doesn't actually pretty print to the jenkins log
181                STDERR.puts msg.pretty_inspect
[9ffa6b4]182            else
183                STDERR.puts msg
[86d3587]184            end
185        end
[ea215a9]186    end
187
[5ad4022]188    provisioners_env = {
189        "NETPREFIX"                 => NETPREFIX,
190        "BRANCH"                    => BRANCH,
[6a830177]191        "OGBOOT_BRANCH"             => ENV['OGBOOT_BRANCH'],
[5ad4022]192        "GITEA_TOKEN"               => GITEA_TOKEN,
193        "GITEA_USER"                => GITEA_USER,
194        "DHCPNET"                   => DHCPNET,
195        "SSH_GIT_KEY_PASS"          => SSH_GIT_KEY_PASS,
196        "LOCALWEBPORT"              => LOCALWEBPORT,
197        "DEFAULT_UDS_REST_URL"      => ENV['DEFAULT_UDS_REST_URL'],
198        "DEFAULT_UDS_AUTHENTICATOR" => ENV['DEFAULT_UDS_AUTHENTICATOR'],
199        "DEFAULT_UDS_USER"          => ENV['DEFAULT_UDS_USER'],
[8c1f4cf]200        "DEFAULT_UDS_PASS"          => ENV['DEFAULT_UDS_PASS'],
[a984630]201        "OGLOG_IP"                  => ENV['OGLOG_IP'],
[8c1f4cf]202        "OGSERVER_IP"               => ENV['OGSERVER_IP'],
[5ad4022]203    }
[039b4d8]204    app_servers = {
[4fa8ce3]205        'vm1' => {
[6a830177]206            :name               => "og-#{BRANCH_EXTRA}-server",
[5ad4022]207            :memsize            => SERVERMEM,
208            :clone_from         => 'Ubuntu-18-template-image',
209            :networks           => [ 'vLan_742', BRANCH_EXTRA ],
210            :macs               => [ "#{MACPREFIX}:00", "#{MACPREFIX}:01" ],
211            :file_provisioner   => {
[0c52391]212                :src => "config/01-eth1.yaml",
213                :dst => "/tmp/",
214            },
[5ad4022]215            :shell_provisioners => [ OGSERVERSCRIPT ],
[7073c13]216        },
[edae476]217    }
[4f70c64]218
219    vm1 = vm2 = []
220
221    if ENV.has_key?("VM1_COMPONENTS") then
222        vm1 = ENV["VM1_COMPONENTS"].split(" ")
223    end
224
225    if ENV.has_key?("VM2_COMPONENTS") then
226        vm2 = ENV["VM2_COMPONENTS"].split(" ")
227        if vm2.size > 0 then
228            app_servers['vm2'] = {
[c3e28cfe]229                :name               => "og-#{BRANCH_EXTRA}",
[4f70c64]230                :memsize            => SERVERMEM,
231                :clone_from         => 'Ubuntu-18-template-image',
232                :networks           => [ 'vLan_742' ],
233                :macs               => [ "#{MACPREFIX}:02" ],
234                :shell_provisioners => [],
235            }
236        end
237    end
[9ffa6b4]238    do_debug ("VM1_COMPONENTS: " + vm1.to_s)
239    do_debug ("VM2_COMPONENTS: " + vm2.to_s)
[4f70c64]240
[4fa8ce3]241    if vm1.include?("oglog") then
[6a830177]242        app_servers['vm1'][:name] += '-log'
[4fa8ce3]243        app_servers['vm1'][:shell_provisioners].push (OGLOGSCRIPT)
244    end
[4f70c64]245    if vm1.include?("ogdhcp") then
[6a830177]246        app_servers['vm1'][:name] += '-dhcp'
[4fa8ce3]247        app_servers['vm1'][:shell_provisioners].push (OGDHCPSCRIPT)
[4f70c64]248    end
249    if vm1.include?("ogboot") then
[6a830177]250        app_servers['vm1'][:name] += '-boot'
[4fa8ce3]251        app_servers['vm1'][:shell_provisioners].push (OGBOOTSCRIPT)
[4f70c64]252    end
253    if vm1.include?("ogrepo") then
[6a830177]254        app_servers['vm1'][:name] += '-repo'
[4fa8ce3]255        app_servers['vm1'][:shell_provisioners].push (OGREPOSCRIPT)
[4f70c64]256    end
257
[4fa8ce3]258    if vm2.include?("oglog") then
[6a830177]259        app_servers['vm2'][:name] += '-log'
[4fa8ce3]260        app_servers['vm2'][:shell_provisioners].push (OGLOGSCRIPT)
261    end
[4f70c64]262    if vm2.include?("ogdhcp") then
[6a830177]263        app_servers['vm2'][:name] += '-dhcp'
[4f70c64]264        app_servers['vm2'][:shell_provisioners].push (OGDHCPSCRIPT)
265    end
266    if vm2.include?("ogboot") then
[6a830177]267        app_servers['vm2'][:name] += '-boot'
[4f70c64]268        app_servers['vm2'][:shell_provisioners].push (OGBOOTSCRIPT)
269    end
270    if vm2.include?("ogrepo") then
[6a830177]271        app_servers['vm2'][:name] += '-repo'
[4f70c64]272        app_servers['vm2'][:shell_provisioners].push (OGREPOSCRIPT)
273    end
274
[6a830177]275    do_debug (app_servers)
[4f70c64]276
[0c52391]277    app_servers.each do |machine,data|
278        boxname = data[:name]
279        config.vm.define boxname do |og|
[039b4d8]280            og.vm.provider :vmware_esxi do |esxi|
281                esxi.guest_name = boxname
[0c52391]282                esxi.guest_memsize = data[:memsize]
[039b4d8]283                esxi.esxi_username = 'root'
284                esxi.esxi_password = ESXIPASSWORD
285                esxi.esxi_hostname = 'esxi-jenkins.evlt.uma.es'
[0c52391]286                esxi.clone_from_vm = data[:clone_from]
[039b4d8]287                esxi.esxi_resource_pool = "/"
288                esxi.local_allow_overwrite = 'True'
289                esxi.guest_custom_vmx_settings = [['monitor.allowLegacyCPU', 'TRUE']]
290                esxi.guest_storage = [ 10 ]
[0c52391]291                esxi.esxi_virtual_network = data[:networks]
292                esxi.guest_mac_address = data[:macs]
[039b4d8]293                esxi.guest_nic_type = 'e1000'
294            end
295            og.vm.box = "esxi_clone/dummy"
296            og.vm.hostname = boxname
[0c52391]297            if data.key?(:file_provisioner)
298                og.vm.provision "file", source: data[:file_provisioner][:src], destination: data[:file_provisioner][:dst]
299            end
[5ad4022]300            data[:shell_provisioners].each do |script|
301                og.vm.provision "shell", inline: script, env: provisioners_env
302            end
[039b4d8]303        end
304    end
[3a0f599]305end
Note: See TracBrowser for help on using the repository browser.