How to force VM created with an ARM template + Cus

2019-01-20 18:19发布

The CI/CD process:

  1. compiles an executable and uploads it to Azure Storage.
  2. Uploads the "custom script" (that downloads the executable and runs it) to Azure Storage.
  3. Deploys an ARM template of a VM that has a CustomScriptExtension that downloads and runs the custom script.

The subsequent builds update the script and the executable but the VM doesn't pull down the updated script. How to make it redownload and run the script that would run the updated executable?

1条回答
我命由我不由天
2楼-- · 2019-01-20 18:26

In order for the CustomScriptExtension to be executed on an existing VM, the configuration of that extension must be "different" than the last time it was deployed - if it looks the same, i.e. every property value in the json resource is the same as the last time, the extension is not reapplied.

There are two simple ways you can make the configuration "different".

1) is change any property value in the resource, this might not always be practical (and in some cases the opposite of what you really want to do) so the most reasonable property to change is the fileUris property. Generally this property contains a sasToken, that is generated for that particular deployment. Since the sasToken is different each time the property value changes and the extension is re-applied. You can see a sample of this here:

https://github.com/bmoore-msft/AzureRM-Samples/tree/master/VMCSEInstallFilePS

Look at the scripts in the root, that deploy the template.

2) If #1 doesn't fit the workflow, you can control this a little more by using the forceUpdateTag property on the resource. You "seed" this value with whatever string you want on the first deployment and then change the value on a subsequent deployment to re-apply the extension. So for example, you could use a parameter and increment that value whenever you wanted to force a change.

enter image description here

HTH

查看更多
登录 后发表回答