cloud-init是否有办法强制执行订单?

时间:2017-09-15 20:04:01

标签: linux debian cloud-init

我正在运行Debian 9.1,我想使用cloud-init在创建时配置我的VPS,我有一个特定的配置问题。

这是来自提供的快照的cloud.cfg的默认值:

# The modules that run in the 'init' stage
cloud_init_modules:
 - migrator
 - seed_random
 - bootcmd
 - write-files
 - growpart
 - resizefs
 - disk_setup
 - mounts
 - 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 my cloud config ready event
# this can be used by upstart jobs for 'start on cloud-config'.
 - emit_upstart
 - ssh-import-id
 - locale
 - set-passwords
 - grub-dpkg
 - apt-pipelining
 - apt-configure
 - ntp
 - timezone
 - disable-ec2-metadata
 - runcmd
 - byobu

# The modules that run in the 'final' stage
cloud_final_modules:
 - package-update-upgrade-install
 - fan
 - puppet
 - chef
 - salt-minion
 - mcollective
 - 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

如您所见,runcmd将在apt-configure之后的config阶段执行。

作为我的配置的一部分,我正在安装多个软件包,其中一个软件包要求我添加新的源代码并从密钥服务器导入密钥。有一个问题,因为导入密钥需要在系统上安装dirmngr,但默认情况下Debian 9.1没有安装它。

但是,由于apt-configure在runcmd之前执行,因此在尝试导入密钥之前无法安装dirmngr。因此,配置的其余部分将失败,系统将处于不需要的状态。

如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

关于Debian 9.1上缺少dirmngr包导致apt-configure模块失败的特定情况,我已成功将以下bootcmd条目添加到cloud-init条目配置:

# APT fails to acquire GPG keys if package dirmngr is missing
bootcmd:
  - [ cloud-init-per, once, dirmngr-aptupdate, apt-get, update ]
  - [ cloud-init-per, once, dirmngr-aptinstall, apt-get, install, dirmngr ]

由于cloud-init配置是从网络获得的(我使用的是EC2 userdata),因此在执行bootcmd时保证网络正常运行。 cloud-init-per程序可以轻松确保在进一步的实例启动时不会重新执行这些命令。

相关问题