question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(Custom Script Extension) Script failure causes following ARM template deployment to fail

See original GitHub issue

When a script invoked by the Custom Script extension returns an error code, I’ve observed that the next ARM template deployment will also fail. The real problem is that the VM is the resource that fails. This poses a problem for custom scripts executed in ARM template deployments, because the custom script dependsOn the VM. So, it will never run again and have a chance to correct itself. (We use a timestamp in settings to ensure the script runs on each deployment).

Here’s the error output from New-AzureRmResourceGroupDeployment:

VERBOSE: 12:41:22 AM - Create template deployment 'azuredeploy-####-####'.
VERBOSE: 12:41:30 AM - Resource Microsoft.Network/virtualNetworks '#####' provisioning status is succeeded
VERBOSE: 12:41:33 AM - Resource Microsoft.Storage/storageAccounts '#####' provisioning status is succeeded
VERBOSE: 12:41:33 AM - Resource Microsoft.Network/publicIPAddresses '#####' provisioning status is succeeded
VERBOSE: 12:41:36 AM - Resource Microsoft.Compute/virtualMachines '#####' provisioning status is running
VERBOSE: 12:41:36 AM - Resource Microsoft.Network/networkInterfaces '#####' provisioning status is succeeded
New-AzureRmResourceGroupDeployment : 12:42:12 AM - Resource Microsoft.Compute/virtualMachines '#####' failed with message 'The resource 
operation completed with terminal provisioning state 'Failed'.'
At C:\#####\scripts\Deploy.ps1:65 char:11
+ $deploy = New-AzureRmResourceGroupDeployment -Name ((Get-ChildItem $T ...
+           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Resources.NewAzureResourceGroupDeploymentCommand

New-AzureRmResourceGroupDeployment : 12:42:12 AM - VM has reported a failure when processing extension 'shexec'. Error message: "Script returned an 
error.
---stdout---
---errout---
(error output)
".
At C:\#####\scripts\Deploy.ps1:65 char:11
+ $deploy = New-AzureRmResourceGroupDeployment -Name ((Get-ChildItem $T ...
+           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Resources.NewAzureResourceGroupDeploymentCommand

We can work around this problem by invoking custom scripts outside of ARM templates, but it still means we need an extra deploy to fix the issue. Alternatively, I think that we can invoke “/bin/true” after a failed ARM template deployment to get the extension back into a non-error state. However, I can see this issue affecting others, and working around it in this manner is non-intuitive.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
alexandreweisscommented, Mar 15, 2018

Ok so what can we do when the VMSS is in Failed state and the extension cannot be played again ?

0reactions
alexandreweisscommented, Mar 18, 2018

Just talk to VMSS team. My mistake ! I was running the extension as a top level resource of my template , depending on (using “Depends on” property) the VMSS which was in “Failed” state so execution could never happen. I moved extension to be part of the extensionProfile of the VMSS and now it works as a charm. I am able to trigger the extension many times even if last exit RC is >0. Thanks again !

Read more comments on GitHub >

github_iconTop Results From Across the Web

ARM Template - Custom Script Extension Error - Microsoft Q&A
Task failed while creating or updating the template deployment. Below is the portion of Custom Script Extension being used: "condition": ...
Read more >
Azure ARM - Custom Script Extension - Failing randomly
Well, this clearly says: script exited with code 1. this means that the script itself fails. so you need to login to the...
Read more >
Multiple ARM template VM Custom Script Extension post ...
I was running into this often with error of “code: Bad Request, message: Multiple VMExtensions per handler not supported for OS type 'Windows'.”....
Read more >
Azure Custom Script Extension On Linux VM and VMSS
In this way extension will be deployed only after VMSS. NOTE: Changing timestamp property in the ARM template and redeploying causes script to ......
Read more >
Blog - Jason Masten
Problem: During an Azure deployment, you receive the following error with the Custom Script Extension: “Provisioning of VM extension CustomScriptExtension has ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found