1 Reply Latest reply on May 31, 2019 5:16 AM by Touffi

    How to pass variables from %pre to %firstboot on ESXi 6.7U1 with kickstart

    Korstiaan201110141 Lurker

      Hi,

       

      Does anyone knows how to pass (keep) variables set in the %pre section to use in the %firstboot (and maybe %post) section?

      If I save them as files in /tmp or /etc they get deleted.

       

      Is that even possible?

       

      Korstiaan

        • 1. Re: How to pass variables from %pre to %firstboot on ESXi 6.7U1 with kickstart
          Touffi Enthusiast

          Hi Korstiaan,

           

          I think it is simple!

          • %pre

                    define your variable and create a file variable you can later call

          • %post

                    tar the variable file  on the persistent directory /vmfs/volumes/datastore1/

          • %firstboot

                     untar this file and call it

           

          I change today my kickstart file to achieve this goal and it's work well:

           

          # ###################### Example #########################

          %pre

          DNS1=$(echo "my first dns ip")              # 1st DNS Server
          DNS2=$(echo "my second dns ip")        # 2nd DNS Server
          HOSTNAME=$(echo "my.server.mydomain.ch") # Server Name
          NTPSTICKER=$(echo "my.ntp.ch")        # ntp server

          # #################### /tmp/yourfile ########################
          # Send all Variables in a file for use with firstboot section

          echo DNS1="${DNS1}" >> /tmp/yourfile
          echo DNS2="${DNS2}" >> /tmp/yourfile
          echo HOSTNAME="${HOSTNAME}" >> /tmp/yourfile

           

          %post --interpreter=busybox
          # copy file / tar dir / cp tgz to a persistent datastore /vmfs/volumes/datastore1/

          # after reboot the file stay in this place


          cp /tmp/yourfile /YourDirectory/yourfile

          tar -czvf YourTGZ.tgz -C / YourDirectory/
          chmod 755 YourTGZ.tgz
          cp YourTGZ.tgz /vmfs/volumes/datastore1/YourTGZ.tgz


          %firstboot --interpreter=busybox

          # you untar YourTGZ and use in your fallowing scripts

          tar -xzvf /vmfs/volumes/datastore1/YourTGZ.tgz

           

          # you can delete yourtgz if you want or copy somewhere to keep it as archive
          rm -f /vmfs/volumes/datastore1/YourTGZ.tgz

           

          # you can call Your file in your script in this way, take care to the space between the dot and the slash

          . /Yourfile

          ########################################################

           

          Best Regards

          Denis