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

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

问题描述

CI/CD流程:

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

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

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?

推荐答案

要在现有VM上执行CustomScriptExtension,该扩展的配置必须与上次部署时不同"(如果已配置)看起来相同,即json资源中的每个属性值都与上一次相同,因此不会重新应用扩展名.

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

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)如果#1不适合工作流程,则可以通过使用资源上的forceUpdateTag属性来对此进行更多控制.您可以在第一个部署中使用所需的任何字符串播种"该值,然后在后续部署中更改该值以重新应用扩展.因此,例如,您可以使用参数并在需要强制更改时增加该值.

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天全站免登陆