After installing cloud-init, you need to update the configuration files as follows:
Procedure
Open the cloud-init configuration file /etc/cloud/cloud.cfg
and update the following configuration items:
Enable the root account and set it as the default user for cloud-init:
default_user:
name: root
lock_passwd: false
disable_root: false
ssh_pwauth: true
chpasswd:
expire: false
Set the cloud-init data source to config drive
:
datasource_list: [ConfigDrive, None]
datasource:
ConfigDrive:
dsmode: local
Comment out growpart
and resizefs
to disable the cloud-init auto extension partition modules:
# - growpart
# - resizefs
Below is the example of the configuration of cloud-init-18.5-3.el7.centos.x86_64
on CentOS 7.4:
users:
- default
#Modify disable_root, ssh_pwauth, chpasswd, datasource_list, datasource ==>
disable_root: false
ssh_pwauth: true
chpasswd:
expire: false
datasource_list: [ConfigDrive, None]
datasource:
ConfigDrive:
dsmode: local
#<==The modification ends here
mount_default_fields: [~, ~, 'auto', 'defaults,nofail,x-systemd.requires=Cloud-init.service', '0', '2']
resize_rootfs_tmp: /dev
ssh_deletekeys: 0
ssh_genkeytypes: ~
syslog_fix_perms: ~
disable_vmware_customization: false
cloud_init_modules:
- disk_setup
- migrator
- bootcmd
- write-files
#Comment out the following two items
# - growpart
# - resizefs
- set_hostname
- update_hostname
- update_etc_hosts
- rsyslog
- users-groups
- ssh
cloud_config_modules:
- mounts
- locale
- set-passwords
- rh_subscription
- yum-add-repo
- package-update-upgrade-install
- timezone
- puppet
- chef
- salt-minion
- mcollective
- disable-ec2-metadata
- runcmd
cloud_final_modules:
- rightscale_userdata
- scripts-per-once
- scripts-per-boot
- scripts-per-instance
- scripts-user
- ssh-authkey-fingerprints
- keys-to-console
- phone-home
- final-message
- power-state-change
system_info:
#Modify default_user ==>
default_user:
name: root
lock_passwd: false
#<==The modification ends here
distro: rhel
paths:
cloud_dir: /var/lib/cloud
templates_dir: /etc/cloud/templates
ssh_svcname: sshd
# vim:syntax=yaml
When a virtual machine boots too fast, especially when the cluster where it resides has Boost mode enabled, cloud-init might be unexpectedly booted before the config drive
is mounted, which makes DataSource
undetectable. To prevent this issue, you will need to open the configuration file at /usr/lib/systemd/system/cloud-init-local.service
and add ExecStartPre=/bin/sleep 2
to its content.