2017-09-15 123 views
1

我正在運行Debian 9.1,我想通過使用cloud-init在創建時配置我的VPS,並且我有一個特定的配置問題。cloud-init有沒有辦法強制執行命令?

這是所提供的快照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-配置後執行。

作爲我的配置的一部分,我安裝了多個軟件包,其中一個需要我添加一個新源並從keyserver導入一個密鑰。有一個問題,因爲導入一個密鑰需要在系統上安裝dirmngr,但Debian 9.1沒有默認安裝它。

但是,由於apt-configure在runcmd之前執行,所以在嘗試導入密鑰之前,我無法安裝dirmngr。因此,其餘配置將失敗,系統將處於不需要的狀態。

我該如何解決這個問題?由於獲得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 ] 

回答

1

關於在Debian 9.1失蹤dirmngr包導致apt-configure模塊出現故障的具體情況,我曾與添加以下bootcmd進入到我的cloud-init配置成功從網絡(我使用EC2用戶數據),當bootcmd被執行時,網絡保證可用。 cloud-init-per程序可以很容易地確保這些命令在進一步的實例啓動時不會被重新執行。

相關問題