如何强制使用 ARM 模板 + CustomScriptExtension 创建的 VM 重新下载脚本并运行它? [英] How to force VM created with an ARM template + CustomScriptExtension to redownload the script and run it?

查看:23
本文介绍了如何强制使用 ARM 模板 + CustomScriptExtension 创建的 VM 重新下载脚本并运行它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CI/CD 流程:

  1. 编译可执行文件并将其上传到 Azure 存储.
  2. 将自定义脚本"(下载可执行文件并运行)上传到 Azure 存储.
  3. 部署 VM 的 ARM 模板,该模板具有下载并运行自定义脚本的 CustomScriptExtension.

后续构建更新脚本和可执行文件,但 VM 不会拉下更新的脚本.如何让它重新下载并运行将运行更新后的可执行文件的脚本?

解决方案

为了在现有 VM 上执行 CustomScriptExtension,该扩展的配置必须与上次部署时不同" - 如果它看起来一样,即json资源中的每个属性值都和上次一样,没有重新应用扩展.

有两种简单的方法可以使配置不同".

1) 是更改资源中的任何属性值,这可能并不总是实用(在某些情况下与您真正想要做的相反),因此最合理的更改属性是 fileUris 属性.通常,此属性包含为该特定部署生成的 sasToken.由于每次属性值更改时sasToken 都不同,因此重新应用扩展名.您可以在此处查看示例:

HTH

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?

解决方案

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.

HTH

这篇关于如何强制使用 ARM 模板 + CustomScriptExtension 创建的 VM 重新下载脚本并运行它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆