VMware Cloud Community
vin01
Expert
Expert
Jump to solution

vmware Photon OS 3.0 Customization

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
Regards Vineeth.K
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
36 Replies
LucD
Leadership
Leadership
Jump to solution

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.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

vin01
Expert
Expert
Jump to solution

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:

pastedImage_1.png

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

Regards Vineeth.K
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vin01
Expert
Expert
Jump to solution

I got same error after using attached json file.

pastedImage_0.png

Regards Vineeth.K
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

vin01
Expert
Expert
Jump to solution

I just executed this in ISE but giving same error

pastedImage_0.png

Regards Vineeth.K
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I suspect you missed my last update.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vin01
Expert
Expert
Jump to solution

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

Now its working

pastedImage_0.png

I will execute complete script and post you update

Regards Vineeth.K
Reply
0 Kudos
vin01
Expert
Expert
Jump to solution

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

pastedImage_0.png

Regards Vineeth.K
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

vin01
Expert
Expert
Jump to solution

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.

pastedImage_0.png

Regards Vineeth.K
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vin01
Expert
Expert
Jump to solution

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

pastedImage_1.png

pastedImage_2.png

Attached .json file which is used.

Regards Vineeth.K
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vin01
Expert
Expert
Jump to solution

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.

pastedImage_0.png

Regards Vineeth.K
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vin01
Expert
Expert
Jump to solution

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?

Regards Vineeth.K
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, please try that


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vin01
Expert
Expert
Jump to solution

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.

pastedImage_0.png

Regards Vineeth.K
Reply
0 Kudos