【问题标题】:Why does Azure VM not run cloud-init script specified in userData parameter?为什么 Azure VM 不运行 userData 参数中指定的 cloud-init 脚本?
【发布时间】:2022-04-13 23:19:57
【问题描述】:

将 ARM 模板 https://pastebin.com/ShjazbpR 与 cloud-init 脚本一起使用:

#cloud-config

# Install additional packages on first boot
#
# Default: none
#
# if packages are specified, this apt_update will be set to true
#
# packages may be supplied as a single package name or as a list
# with the format [<package>, <version>] wherein the specifc
# package version will be installed.
packages:
 - pwgen

不安装 pwgen 包,也不更新包列表,因为文档 https://cloudinit.readthedocs.io/en/latest/topics/examples.html#install-arbitrary-packages 指出它应该更新包列表:# if packages are specified, this apt_update will be set to true

如果我在此模板https://pastebin.com/27s4pgiD 中使用osProfile 下的customData 属性,一切都会按预期工作,pwgen 已安装并且包列表在首次启动时更新。

有谁知道为什么 userData 不起作用? Azure 文档 https://docs.microsoft.com/azure/virtual-machines/user-data 声明 Azure 支持 userData。

【问题讨论】:

    标签: azure user-data cloud-init


    【解决方案1】:

    仅自定义数据支持自动云初始化。如果您使用用户数据,那么它被视为原始数据,您必须自己获取并处理它。例如,您可以在映像中有一个脚本在启动时运行(仅第一次运行,或者也重新启动),用于获取和处理这些数据。

    例如:

    curl -H Metadata:true --noproxy "*" "http://169.254.169.254/metadata/instance/compute/userData?api-version=2021-01-01&format=text" | base64 --decode >> somefile
    #process somefile...
    

    https://docs.microsoft.com/en-us/azure/virtual-machines/linux/instance-metadata-service?tabs=linux#get-user-data

    【讨论】:

      猜你喜欢
      • 2014-06-05
      • 1970-01-01
      • 2019-12-18
      • 2019-02-08
      • 2023-03-28
      • 2018-05-13
      • 1970-01-01
      • 2012-08-27
      • 1970-01-01
      相关资源
      最近更新 更多