Hello Harsh Jivani,
Welcome to the Microsoft Q&A and thank you for posting your questions here.
Problem
I understand that you are having issues with deploying a new Linux VM using a PowerShell script and a JSON template. Especially, to resolve 'patchSettings' error when creating new Linux VM and steps to include the 'linuxConfiguration' block in my script.
Solution
To resolve the 'patchSettings' Error and include the 'linuxConfiguration' block in your script:
- The error you're encountering is related to the
patchSettings
parameter within thelinuxConfiguration
block. To set thepatchMode
to 'ImageDefault' (instead of 'AutomaticByPlatform'), follow these steps: - Ensure that you have separate sections for Windows and Linux configurations.
- Define the 'linuxConfiguration' block under the 'osProfile' section for your Linux VM.
- In your JSON template, ensure that you have the
linuxConfiguration
section defined correctly. It should look something like this:"osProfile": { "computerName": "mylinuxvm", "adminUsername": "myadminuser", "linuxConfiguration": { "disablePasswordAuthentication": true, "patchSettings": { "patchMode": "ImageDefault" } }
- Make sure you include this block within your VM resource definition.
- When deploying the VM using your PowerShell script, ensure that you pass the correct values for the
linuxConfiguration
section. Verify that thepatchMode
is set to 'ImageDefault'. - If you're still encountering issues, double-check the rest of your template and ensure there are no conflicting settings or typos.
To use a PowerShell script and a JSON template to create your Linux VM. Here are the steps:
- Create a JSON file that defines your VM configuration. For an example:
{
"apiVersion": "2022-03-01",
"type": "Microsoft.Compute/virtualMachines",
"name": "myLinuxVM",
"location": "East US",
"properties": {
"osProfile": {
"computerName": "myLinuxVM",
"adminUsername": "myadminuser",
"adminPassword": "MySecurePassword123"
},
"hardwareProfile": {
"vmSize": "Standard_B1s"
},
// Other properties...
}
}
- Customize the properties according to your requirements.
Include the ‘linuxConfiguration’ Block inside the properties section, add the following block to configure the Linux VM:
"storageProfile": {
// Storage profile settings...
},
"osProfile": {
// OS profile settings...
},
"linuxConfiguration": {
"disablePasswordAuthentication": true,
"patchSettings": {
"patchMode": "AutomaticByOS",
"assessmentMode": "ImageDefault"
}
}
Adjust the properties as needed (e.g., SSH key instead of password).
- Deploy Using PowerShell for example, ue the following PowerShell script to deploy the VM:
$resourceGroupName = "myResourceGroup"
$templateFile = "path/to/your/template.json"
New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateFile $templateFile
Replace the file path and resource group name with your actual values.
Note:
- The provided example is simplified version. Make sure to include all necessary properties and customize it for your environment.
- If you encounter the ‘patchSettings’ error, ensure that the linuxConfiguration block is correctly included in your template.
Accept Answer
I hope this is helpful! Do not hesitate to let me know if you have any other questions.
** Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful ** so that others in the community facing similar issues can easily find the solution.
Best Regards,
Sina Salam