cloud-init:cloud-config指令的执行顺序是什么?

44

在 cloud-init 用户数据对象的 cloud-config 部分中,指令的顺序是什么。这很重要,可以避免竞争条件。

我知道 bootcmd 会早些时候运行,并在 runcmd 之前运行,但是否有所有方法顺序的好列表?

1个回答

51

来自https://git.launchpad.net/cloud-init/tree/config/cloud.cfg(感谢garbelini)

(截至2017年9月,上述链接不正确,现在为https://git.launchpad.net/cloud-init/tree/config/cloud.cfg.tmpl,请参见下面的说明)

# The modules that run in the 'init' stage
cloud_init_modules:
 - migrator
 - ubuntu-init-switch
 - seed_random
 - bootcmd
 - write-files
 - growpart
 - resizefs
 - set_hostname
 - update_hostname
 - update_etc_hosts
 - ca-certs
 - rsyslog
 - users-groups
 - ssh

# The modules that run in the 'config' stage
cloud_config_modules:
# Emit the cloud config ready event
# this can be used by upstart jobs for 'start on cloud-config'.
 - emit_upstart
 - disk_setup
 - mounts
 - ssh-import-id
 - locale
 - set-passwords
 - snappy
 - grub-dpkg
 - apt-pipelining
 - apt-configure
 - package-update-upgrade-install
 - fan
 - landscape
 - timezone
 - lxd
 - puppet
 - chef
 - salt-minion
 - mcollective
 - disable-ec2-metadata
 - runcmd
 - byobu

# The modules that run in the 'final' stage
cloud_final_modules:
 - rightscale_userdata
 - scripts-vendor
 - scripts-per-once
 - scripts-per-boot
 - scripts-per-instance
 - scripts-user
 - ssh-authkey-fingerprints
 - keys-to-console
 - phone-home
 - final-message
 - power-state-change

此外:

存在配置合并"顺序如下: - cli 配置文件覆盖环境配置文件, 环境配置文件覆盖实例配置文件,实例配置文件覆盖数据源配置文件, 数据源配置文件覆盖基础配置文件,基础配置文件覆盖默认配置文件。" (参见 Changelog)

在各自生成的脚本目录中,脚本将按照Python "sorted()" 内置函数给出的顺序运行。

注意:尽管在回答时这是正确的,但是查看上面提到的库(截至2017年9月),现在有一个cloud.cfg.tmpl模板文件,其中对不同的发行版设置略有不同。

# The modules that run in the 'init' stage
cloud_init_modules:
 - migrator
 - seed_random
 - bootcmd
 - write-files
 - growpart
 - resizefs
{% if variant not in ["freebsd"] %}
 - disk_setup
 - mounts
{% endif %}
 - set_hostname
 - update_hostname
{% if variant not in ["freebsd"] %}
 - update_etc_hosts
 - ca-certs
 - rsyslog
{% endif %}
 - users-groups
 - ssh

# The modules that run in the 'config' stage
cloud_config_modules:
{% if variant in ["ubuntu", "unknown", "debian"] %}
# Emit the cloud config ready event
# this can be used by upstart jobs for 'start on cloud-config'.
 - emit_upstart
 - snap_config
{% endif %}
 - ssh-import-id
 - locale
 - set-passwords
{% if variant in ["rhel", "fedora"] %}
 - spacewalk
 - yum-add-repo
{% endif %}
{% if variant in ["ubuntu", "unknown", "debian"] %}
 - grub-dpkg
 - apt-pipelining
 - apt-configure
{% endif %}
{% if variant not in ["freebsd"] %}
 - ntp
{% endif %}
 - timezone
 - disable-ec2-metadata
 - runcmd
{% if variant in ["ubuntu", "unknown", "debian"] %}
 - byobu
{% endif %}

# The modules that run in the 'final' stage
cloud_final_modules:
{% if variant in ["ubuntu", "unknown", "debian"] %}
 - snappy
{% endif %}
 - package-update-upgrade-install
{% if variant in ["ubuntu", "unknown", "debian"] %}
 - fan
 - landscape
 - lxd
{% endif %}
{% if variant not in ["freebsd"] %}
 - puppet
 - chef
 - salt-minion
 - mcollective
{% endif %}
 - rightscale_userdata
 - scripts-vendor
 - scripts-per-once
 - scripts-per-boot
 - scripts-per-instance
 - scripts-user
 - ssh-authkey-fingerprints
 - keys-to-console
 - phone-home
 - final-message
 - power-state-change

有没有一种方法可以强制更改执行顺序?例如,我需要确保在运行apt并尝试导入源密钥之前安装dirmngr(它在我的发行版中缺失),因为否则会失败。然后我想像平常一样继续安装其余的软件包。 - Tristan
1
有没有任何情况下执行顺序不被尊重的情况?在Ubuntu Cloud 16.04镜像中,“runcmd”被放置在“config”阶段,“package-update-upgrade-install”被放置在“final”阶段,但我可以在安装软件包后运行“runcmd”而没有任何错误。 - dvnguyen
1
@Tristan 我注意到现在apt/dpkg配置有三个步骤,也许你可以钩住其中一个? - Vorsprung
1
@dvnguyen 我不确定语义是如何准确运作的。你应该提出一个简单的例子,并寻找真正的专家来解答...听起来很有趣。 - Vorsprung
1
@Vorsprung 我在这里提出了一个问题:https://dev59.com/m6Xja4cB1Zd3GeqPNS-U - dvnguyen
这对于AWS Ubuntu 16.04镜像不正确。runcmd明确发生在安装软件包之后。 - David

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接