PowerCLI

 View Only
Expand all | Collapse all

vmware Photon OS 3.0 Customization

LucD

LucDOct 17, 2019 09:37 AM

  • 1.  vmware Photon OS 3.0 Customization

    Posted Oct 16, 2019 04:42 AM

    I am trying to customize the photon os 3.0 ova as same as guest customization which is done on windows or linux vm.

    Here is the requirement. Is something possible to script it?

    1. We ship  photon ova to the customers for building docker containers.
    2. Once we ship this to customers they will deploy the ova in vcenter cluster by passing all required parameters from a variable or a json file(hostname,ip etc)
    3. Objective is to have all the configuration parameters in a json file and use import-vapp with OvfConfiguration passed from that json file.
    4. After deploying ova using invoke-vmscript and we need to push the code to install docker & other container application


  • 2.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 16, 2019 07:51 AM

    You could start with my posts Deploy Photon 2.0 – Part 1 ​and Deploy Photon 2.0 – Part 2

    It contains most of your requirements.

    In the meantime, I also have presented during the VMworld US session, named  'PowerCLI Deep Dive', how to use cloud-init to deploy and customise Photon.


    On the same subject, there is my chapter in The PowerShell Conference Book Volume 2, that discusses this use of cloud-init further.

    Note that this book is currently not completely published yet.



  • 3.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 16, 2019 11:57 AM

    Hi LucD,

    I have gone through your post part 1 Deploy Photon 2.0 – Part 1 ​  but when i try to execute the New-PhotonTemplate cmdlet its give error ConvertFrom-Json : Invalid JSON primitive: .

    Steps I followed

    1. Created a json file with required parameters.

    2.Saved Invoke-VMScriptPlus & Set-VMKeystrokes scripts in .psm1 format and imported as module (Import-Module "C:\My Data\PhotonOVA\Invoke-photon.psm1" -Force -Scope Global)

    3.Executed like this New-PhotonTemplate -JSONPath "C:\My Data\PhotonOVA\Input.json" -LogFile "C:\My Data\PhotonOVA\log.txt"

    Error:

    I have attached the json flie what i have created in this thread.



  • 4.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 16, 2019 12:03 PM

    You seem to have a syntax error in the JSON file.

    That last part should be

        "Code": [

          {

            "Name": "PowerCLI",

            "Script": ["docker pull vmware/powerclicore"],

             "Environment": ["MSG=Hellow World"]

          } 

        ]

    I attached the corrected file



  • 5.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 16, 2019 12:10 PM

    I got same error after using attached json file.



  • 6.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 16, 2019 12:15 PM

    Just noticed there was a 2nd syntax error in the JSON file.
    Corrected file attached.

    As a hint, you can use the online JSONLint page to validate your JSON files.



  • 7.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 16, 2019 12:25 PM

    I just executed this in ISE but giving same error



  • 8.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 16, 2019 12:28 PM

    I suspect you missed my last update.



  • 9.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 16, 2019 12:35 PM

    Oops I missed it. Right after posting my reply I got this update.

    Now its working

    I will execute complete script and post you update



  • 10.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 16, 2019 01:39 PM

    I tried like this but why it is not taking .json flie path into $JSONPath variable. Due to this its showing argument is empty.



  • 11.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 16, 2019 02:17 PM

    There are 2 errors:

    1. The JSON template I posted has vSphere.Location, while the script uses vSphere.VMHost. Change the JSON file or the script.
    2. You need to do a Connect-VIServer before calling the function

    I will update the JSON template in my post.



  • 12.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 16, 2019 03:56 PM

    This time I can able to import ovf but its failing at guest customization.

    Keystrokes also send successfully as I can see password changed to desired one which i mentioned json file.



  • 13.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 16, 2019 04:06 PM

    That 1st error seems to indicate that the default harddisk size is bigger than what you specified in the JSON file.
    Which OVA file are you using?

    The Invoke-VMScriptPlus errors come from the fact that you only added 1 script to the JSON file (under Code).

    But under Template.CustomisationCode you are calling 4 scripts, hence the 3 errors complaining about an empty ScriptText parameter value.



  • 14.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 17, 2019 07:53 AM

    Which OVA file are you using?

    photon-hw11-3.0-26156e2.ova. Its version 3.0

    I have corrected 1st error of default harddisk size by changing it to 20GB

    Now I can able to deploy the vm and keystrokes are issued correctly(Password change is done) but its failing at guest customization.

    I have validated the json file and its showing valid but I received exception message at line 323 in invoke-vmscriptplus

    Attached .json file which is used.



  • 15.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 17, 2019 09:06 AM

    Your JSON file is ok now.

    That error is most probably from Invoke-VMScriptPlus.
    I had something similar on occasion.

    Do you get that same error at every run?

    With me that error most of the time didn't occur on subsequent runs.



  • 16.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 17, 2019 09:11 AM

    I have executed twice and I got same error.

    At first execution I even got Exception calling "PutUsbScanCodes" but after second time executing I didn't see that error.



  • 17.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 17, 2019 09:17 AM

    And the photon VM's root password has been changed, even when you get the error?



  • 18.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 17, 2019 09:24 AM

    At first execution when i received (Exception calling "PutUsbScanCodes" )the password is not changed but in second time execution the password has changed.

    Should I close complete powershell session and retry?



  • 19.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 17, 2019 09:37 AM

    Yes, please try that



  • 20.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 17, 2019 10:02 AM

    With new session I tried twice but received different errors with each try.

    Sometimes its accepting keystrokes but failing to take script text and in second attempt keystrokes send correctly but failed with exception error.



  • 21.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 17, 2019 10:18 AM

    The 1st error is from the PutUsbScanCodes function.
    Do have Sleep commands between the consecutive calls to PutUsbScanCodes?

    The 2nd series of errors is most probably all a result of the password not having been changed (see the 1st error).

    The 3th error is the inconsistency between the script defined in the JSON file and the scripts you call.

    I mentioned that before.



  • 22.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 17, 2019 10:26 AM

    Not clear why script is giving different error on subsequent runs. This time keystrokes passed correctly but failed to get scripttext correctly.

    I will try with the steps  that you suggested now.



  • 23.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 17, 2019 10:36 AM

    Again, that empty ScriptText error is because you call more customization scripts than you have defined in the JSON file.

    You could also try to increase the sleep time between calls to Send-VMKeystrokes.

    Set-VMKeystrokes -VMName $VM.Name -StringInput $paramData.Account.User -ReturnCarriage $true | Out-Null

    Start-Sleep 1

    Set-VMKeystrokes -VMName $VM.Name -StringInput $paramData.Account.OldPassword -ReturnCarriage $true | Out-Null

    Start-Sleep 1

    Set-VMKeystrokes -VMName $VM.Name -StringInput $paramData.Account.OldPassword -ReturnCarriage $true | Out-Null

    Start-Sleep 1

    Set-VMKeystrokes -VMName $VM.Name -StringInput $paramData.Account.NewPassword -ReturnCarriage $true | Out-Null

    Start-Sleep 1

    Set-VMKeystrokes -VMName $VM.Name -StringInput $paramData.Account.NewPassword -ReturnCarriage $true | Out-Null



  • 24.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 17, 2019 11:14 AM

    After making changes script executed with no errors but guest customization not happened.



  • 25.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 17, 2019 11:26 AM

    Not sure what your current JSON file contains, but I did notice that the redirection symbols, were converted in some way.

    For example

    this

    "cat \u003e /etc/systemd/network/99-dhcp-en.network \u003c\u003c EOF",

    should be

    "cat > /etc/systemd/network/99-dhcp-en.network << EOF",

    If you check, you will probably notice that the file /etc/systemd/network/10-static-en.network does not exist.

    That is one of the files that defines your network configuration



  • 26.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 17, 2019 11:54 AM

    Even after replacing the redirection symbols still Ip is not assigned. Is something other then  redirection symbols to be replaced.

    Attaching the json file which is used and also I have noticed Ip address is updated in 10-static-en.network but not assigned to eth0



  • 27.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 17, 2019 12:03 PM

    Was the file created?



  • 28.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 17, 2019 12:06 PM

    Yes file is created and I see IP address in that file but that is not assigning to eth0



  • 29.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 17, 2019 01:38 PM

    Is the 99-dhcp-en.network file also in that folder?

    Did all the commands in the 'network' script execute correctly?

    You should have a log with the output of each of these customisation scripts.



  • 30.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 17, 2019 02:10 PM

    Is the 99-dhcp-en.network file also in that folder?

    yes I can see 99-dhcp in the folder.

    Did all the commands in the 'network' script execute correctly?

    Yes I have verified rest of the commands executed correctly.

    Logfile attached. Can you check is anything I am missing.



  • 31.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 17, 2019 04:04 PM

    I noticed you don't have the reboot in the JSON file.
    Try adding it to CustomisationCode array in the JSON file.

    You don't have to provide a script for the 'reboot', it is handled in the function.

    "CustomisationCode": [

        "network",

        "docker",

        "PowerCLI",

        "reboot"

    ]



  • 32.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 17, 2019 04:52 PM

    Even after adding reboot still same issue



  • 33.  RE: vmware Photon OS 3.0 Customization
    Best Answer

    Posted Oct 17, 2019 06:24 PM

    You might consider enabling network debugging.

    My sample 'network' script contains the following commented lines.

        "# Network debugging",

        "#mkdir -p /etc/systemd/system/systemd-networkd.service.d/",

        "#cat > /etc/systemd/system/systemd-networkd.service.d/10-loglevel-debug.conf << EOF",

        "#[Service]",

        "#Environment=SYSTEMD_LOG_LEVEL=debug",

        "#EOF",

        "#systemctl daemon-reload",

        "#systemctl restart systemd-networkd",

        "#systemd-delta --type=extended",

        "",

    Remove the comment character, and check what the logs say.

    On photon network debugging you can find more info at Network Debugging



  • 34.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 18, 2019 08:26 AM

    Its my bad sorry. After checking the log file I see the issue is with netmask (in .json I mentioned as 255.255.255.0). Now I corrected and executed.

    What I observed is at vcenter display I can see the configured IP but if i do ifconfig its showing 169** . I think its still taking dhcp as primary address. How to fix this?



  • 35.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 18, 2019 08:36 AM

    Does the Web CLient keep showing 2 IP addresses?

    Even after a restart of the VM?

    Not sure what you are showing there, inside the guest OS the 'ifconfig -a' shows an APIPA address, while the log seems to show that the fixed IP is selected.

    Was the this done after the guest OS was rebooted?
    Did you activate network debugging as I suggested earlier?



  • 36.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 18, 2019 09:33 AM

    Does the Web CLient keep showing 2 IP addresses?

    Yes

    Even after a restart of the VM?

    Yes even after reboot its showing two ips.

    Not sure what you are showing there, inside the guest OS the 'ifconfig -a' shows an APIPA address, while the log seems to show that the fixed IP is selected.

    Was the this done after the guest OS was rebooted?

    yes after reboot only I have checked what ip is configured eth0 and its showing apipa address. but log showing Ip is assigned.

    Did you activate network debugging as I suggested earlier?

    yes I have activated. Here is logfile

    After rebooting OS is picking new address with apipa address

    After the above message eth0 is showing updating address as static ip but again picking apipa address



  • 37.  RE: vmware Photon OS 3.0 Customization

    Posted Oct 18, 2019 11:38 AM

    Finally I found the fix and surprisingly the answer is found from the question you posted in Git.

    IPv4 & IPv6 APIPA addresses generated · Issue #800 · vmware/photon · GitHub

    Fix

    after replacing this it worked.

    LinkLocalAddressing=ipv4 to LinkLocalAddressing=no

    Thanks for your support