How to resolve 'patchSettings' error when creating new Linux VM with PowerShell script and JSON template?

Harsh Jivani 0 Reputation points
2024-07-27T20:52:00.45+00:00

I am attempting to deploy a new Linux VM using a PowerShell script and JSON template, but I am encountering an error related to the 'LinuxConfiguration' object and the 'patchSettings' parameter. Specifically, I want to ensure that 'patchMode' is set to 'ImageDefault' and not 'AutomaticByPlatform', but when I include the 'linuxConfiguration' block in my script it throws an error that it cannot find 'patchSettings'. I have attempted to troubleshoot this issue and discovered that if I remove the 'linuxConfiguration' block from the script, it works as expected since Azure defaults to 'ImageDefault'. What steps can I take to resolve this issue and still include the 'linuxConfiguration' block in my script?

error-linux-imagedefault

User's image

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,996 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,597 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Sina Salam 12,011 Reputation points
    2024-07-28T15:32:22.6166667+00:00

    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 the linuxConfiguration block. To set the patchMode 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 the patchMode 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:

    1. 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...
        }
    }
    
    1. 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).

    1. 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:

    1. The provided example is simplified version. Make sure to include all necessary properties and customize it for your environment.
    2. 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

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.