【问题标题】:cloud-init: What is the execution order of cloud-config directives?cloud-init:cloud-config 指令的执行顺序是什么?
【发布时间】:2016-03-09 19:53:07
【问题描述】:

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

我知道 bootcmd 早在 runcmd 之前运行,但是有没有列出所有方法的顺序的好列表?

【问题讨论】:

    标签: user-data cloud-init


    【解决方案1】:

    来自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 配置文件覆盖环境配置文件 覆盖数据源的实例配置 覆盖基本配置的配置 默认配置。”(参见变更日志)

    在各个生成的脚本目录中,脚本按照内置的 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 (它在我的发行版中丢失),因为它会失败。然后我会继续照常安装其余的包。
    • 有没有不遵守执行顺序的情况?在 Ubuntu Cloud 16.04 映像中,runcmd 被放入 config 阶段,package-update-upgrade-install 被放入 final 阶段,但我可以在安装包后运行 runcmd 而不会出现任何错误。
    • @Tristan 我注意到 apt/dpkg 配置现在有三个步骤,mayeb 你可以钩其中一个吗?
    • @dvnguyen 我不知道语义究竟是如何工作的。你应该用一个简单的例子来打开一个问题,看看你是否能找到一个真正的专家......听起来很有趣
    • @Vorsprung 我在这里提出了一个问题:stackoverflow.com/questions/46230371/…
    猜你喜欢
    • 2020-07-01
    • 2021-11-03
    • 1970-01-01
    • 2021-12-11
    • 1970-01-01
    • 2020-02-14
    • 1970-01-01
    • 1970-01-01
    • 2022-01-02
    相关资源
    最近更新 更多