简体   繁体   English

为什么 Azure VM 不运行 userData 参数中指定的 cloud-init 脚本?

[英]Why does Azure VM not run cloud-init script specified in userData parameter?

Using the ARM template https://pastebin.com/ShjazbpR with the cloud-init script:使用 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

Does not install pwgen package nor does it update package list, as documentation https://cloudinit.readthedocs.io/en/latest/topics/examples.html#install-arbitrary-packages states it should update package list: # if packages are specified, this apt_update will be set to true不安装 pwgen package 也不更新 package 列表,因为文档https://cloudinit.readthedocs.io/en/latest/topics/examples.html#install-arbitrary-packages指出它应该更新 package 列表: # if packages are specified, this apt_update will be set to true

If I use the customData property under osProfile in this template https://pastebin.com/27s4pgiD everything works as expected, pwgen is installed and package list is updated at first boot.如果我在此模板https://pastebin.com/27s4pgiD osProfile使用 osProfile 下的customData属性,一切都按预期工作,安装 pwgen 并在首次启动时更新 package 列表。

Does anyone know why userData is not working?有谁知道为什么 userData 不工作? Azure documentation https://learn.microsoft.com/azure/virtual-machines/user-data states userData is supported in Azure. Azure 文档https://learn.microsoft.com/azure/virtual-machines/user-data指出 Azure 支持 userData。

Automatic cloud init is only supported for custom data.仅自定义数据支持自动云初始化。 If you use user data then it is seen as raw data, and you have to fetch it and handle it yourself.如果您使用用户数据,那么它会被视为原始数据,您必须自己获取并处理它。 For example you can have a script in your image that runs on startup (only first time, or restarts too), that fetches and processes this data.例如,你可以在你的图像中有一个在启动时运行的脚本(只有第一次,或者也重新启动),用于获取和处理这些数据。

For example:例如:

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://learn.microsoft.com/en-us/azure/virtual-machines/linux/instance-metadata-service?tabs=linux#get-user-data https://learn.microsoft.com/en-us/azure/virtual-machines/linux/instance-metadata-service?tabs=linux#get-user-data

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 cloud-init 和实例标签在 EC2 上设置主机名? - Set hostname on EC2 using cloud-init and instance tags? 如何使用 VM 上的文件使用 Azure 数据工厂运行 python 脚本? - How to run python script with Azure Data Factory using files on a VM? 在 gce 中运行云初始化脚本 - running cloud init script in gce 为什么Google Cloud Function HTTP 需要main function 中的一个参数? - Why does Google Cloud Function HTTP need a parameter in the main function? 为什么我的自定义 VM 映像没有显示在 Azure 创建 VM 界面中? - Why does my custom VM Image not show up in Azure Create VM Interface? 为什么我的 Google Cloud TPU VM 实例无法识别 TPU? - Why is the TPU not recognized on my Google Cloud TPU VM instance? 为什么 Google Sign In with Basecamps Gem 在 Google Cloud Run 中不起作用 - Why does Google Sign In with Basecamps Gem not work in Google Cloud Run 在 Cloud Function 的文件中运行 Python 脚本 - Run Python script in a file from Cloud Function Pycharm 在 google.cloud 的“__init__.pyi”中找不到引用“cloud”,但代码确实执行 - Pycharm cannot find reference `cloud` in "__init__.pyi" for google.cloud, but code does execute Codepipeline script_start 失败脚本在指定位置不存在 - Codepipeline script_start failed Script does not exist at specified location
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM