如何手动运行 cloud-init? [英] How to run cloud-init manually?

查看:26
本文介绍了如何手动运行 cloud-init?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写 CloudFormation 模板,并且正在尝试调试我在模板中提供的用户数据脚本.如何手动运行 cloud-init 并使其执行与启动新实例时相同的操作?

I'm writing a CloudFormation template and I'm trying to debug the user-data script I provide in the template. How can I run the cloud-init manually and make it perform the same actions it does when starting a new instance?

推荐答案

你可以这样运行:

/usr/bin/cloud-init -d init

这将使用初始模块运行云初始化设置.(-d 选项用于调试)如果要运行所有必须运行的模块:

This runs the cloud init setup with the initial modules. (The -d option is for debug) If want to run all the modules you have to run:

/usr/bin/cloud-init -d modules

请记住,第二次运行它们时,它并没有做太多事情,因为它已经在启动时运行了.要强制在启动后运行,您可以从命令行运行:

Keep in mind that the second time you run these it doesn't do much since it has already run at boot time. To force to run after boot time you can run from the command line:

( cd /var/lib/cloud/ && sudo rm -rf * )

在旧版本中,cloud-init init 的等效项是:

In older versions the equivalent of cloud-init init is:

/usr/bin/cloud-init start

您可能还会发现这个问题很有用,尽管它适用于旧版本的 cloud-init:如何让 cloud-init 启动脚本在每次 EC2 实例启动时运行?

You may also find this question useful although it applies to the older versions of cloud-init: How do I make cloud-init startup scripts run every time my EC2 instance boots?

cloud init 的文档这里 只是为您提供了示例.但它没有解释命令行选项或每个模块,因此您必须在配置中使用不同的值才能获得所需的结果.当然你也可以看看代码.

The documentation for cloud init here just gives you examples. But it doesn't explain the command line options or each one of the modules, so you have to play around with different values in the config to get your desired results. Of course you can also look at the code.

这篇关于如何手动运行 cloud-init?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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