2.4. Files and directories significant for cloud-init
Red Hat supports the cloud-init utility, cloud-init modules, and default directories and files. By using directories and files, you can perform tasks such as:
-
Configuring
cloud-init -
Finding details about configuration after
cloud-inithas run - Examining log files
- Finding templates
Depending on your requirement and datasource, there can be additional files and directories important to your configuration.
| Directory or File | Description |
|---|---|
|
|
The |
|
|
The |
|
|
When |
|
|
The |
|
|
This directory includes templates that you can enable in |
|
|
The |
|
|
The |
2.4.1. The default cloud.cfg file 复制链接链接已复制到粘贴板!
The /etc/cloud/cloud.cfg file lists the modules included in the basic configuration for cloud-init. These modules are the default modules for cloud-init. You can configure or remove modules based on your requirements.
-
To perform actions during one of the
cloud-initphases, you must configure each module individually and list them in thecloud.cfgfile. Modules run in the order given incloud.cfg. You typically do not change this order. However, you can add additional modules tocloud.cfg, if Red Hat supports the modules that you want to add. -
The
cloud.cfgdirectives can be overridden by user data. When runningcloud-initmanually, you can overridecloud.cfgwith command-line options. - Each module includes its own configuration options, where you can add specific information.
-
To ensure optimal functionality of the configuration, use module names with underscores (
_) rather than dashes (-). - The default contents of the file for Red Hat Enterprise Linux (RHEL) are as follows:
users:
- default
disable_root: true
resize_rootfs_tmp: /dev
ssh_pwauth: false
mount_default_fields: [~, ~, 'auto', 'defaults,nofail,x-systemd.requires=cloud-init.service', '0', '2']
ssh_deletekeys: true
ssh_genkeytypes: ['rsa', 'ecdsa', 'ed25519']
syslog_fix_perms: ~
disable_vmware_customization: false
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
cloud_config_modules:
- ssh_import_id
- locale
- set_passwords
- rh_subscription
- spacewalk
- yum_add_repo
- ntp
- timezone
- disable_ec2_metadata
- runcmd
cloud_final_modules:
- package_update_upgrade_install
- write_files_deferred
- puppet
- chef
- ansible
- mcollective
- salt_minion
- reset_rmc
- rightscale_userdata
- scripts_vendor
- scripts_per_once
- scripts_per_boot
- scripts_per_instance
- scripts_user
- ssh_authkey_fingerprints
- keys_to_console
- install_hotplug
- phone_home
- final_message
- power_state_change
system_info:
default_user:
name: cloud-user
lock_passwd: true
gecos: Cloud User
groups: [adm, systemd-journal]
sudo: ["ALL=(ALL) NOPASSWD:ALL"]
shell: /bin/bash
distro: rhel
network:
renderers: ['sysconfig', 'eni', 'netplan', 'network-manager', 'networkd']
paths:
cloud_dir: /var/lib/cloud
templates_dir: /etc/cloud/templates
ssh_svcname: sshd
# vim:syntax=yaml
-
usersspecifies the default user for the system. For more information, see Users and Groups. -
disable_rootenables or disables root login. For more information, see Authorized Keys. -
ssh_pwauthspecifies whethersshis configured to accept password authentication. For more information, see Set Passwords. -
mount_default_fieldsconfigures mount points. It must be a list containing six values. For more information, see Mounts. -
ssh_deletekeysspecifies whether to remove default host SSH keys. For more information, see Host Keys. -
ssh_genkeytypesspecifies key types to generate. For more information, see Host Keys. -
syslog_fix_permsconfigurescloud-initto log all boot stages to its log file. For more information, see thecloud-config.txtfile in theusr/share/doc/cloud-init/examplesdirectory. -
disable_vmware_customizationenables or disables VMware vSphere customization. -
cloud_init_modules:The modules in this section are services that run when thecloud-initservice starts, early in the boot process. -
cloud_config_modules:These modules run duringcloud-initconfiguration, after initial boot. -
cloud_final_modules:These modules run in the final phase ofcloud-init, after the configuration finishes. -
default_userspecifies details about the default user. For more information. see Users and Groups. -
distro:specifies the distribution. -
cloud_dirspecifies the main directory that containscloud-init-specific subdirectories. For more information, see Directory layout. -
templates_dirspecifies where templates are located. -
ssh_svcnameis the name of the SSH service.
2.4.2. The default cloud.cfg.d directory 复制链接链接已复制到粘贴板!
cloud-init acts upon directives that you provide and configure. Typically, those directives are included in the cloud.cfg.d directory.
While you can configure modules by adding user data directives within the cloud.cfg file, as a best practice consider leaving cloud.cfg unmodified. Add your directives to the /etc/cloud/cloud.cfg.d directory. Adding directives to this directory can make future modifications and upgrades easier.
Refer to User-Data Formats for details on how to add a user script as *.cfg file.
2.4.3. The default 05_logging.cfg file 复制链接链接已复制到粘贴板!
The 05_logging.cfg file sets logging information and the default logging configuration file for cloud-init. The /etc/cloud/cloud.cfg.d directory includes this file, along with other cloud-init directives. The default contents of the file for RHEL are as follows:
## This yaml formatted config file handles setting
## logger information. The values that are necessary to be set
## are seen at the bottom. The top '_log' are only used to remove
## redundancy in a syslog and fallback-to-file case.
##
## The 'log_cfgs' entry defines a list of logger configs
## Each entry in the list is tried, and the first one that
## works is used. If a log_cfg list entry is an array, it will
## be joined with '\n'.
_log:
- &log_base |
[loggers]
keys=root,cloudinit
[handlers]
keys=consoleHandler,cloudLogHandler
[formatters]
keys=simpleFormatter,arg0Formatter
[logger_root]
level=DEBUG
handlers=consoleHandler,cloudLogHandler
[logger_cloudinit]
level=DEBUG
qualname=cloudinit
handlers=
propagate=1
[handler_consoleHandler]
class=StreamHandler
level=WARNING
formatter=arg0Formatter
args=(sys.stderr,)
[formatter_arg0Formatter]
format=%(asctime)s - %(filename)s[%(levelname)s]: %(message)s
[formatter_simpleFormatter]
format=[CLOUDINIT] %(filename)s[%(levelname)s]: %(message)s
- &log_file |
[handler_cloudLogHandler]
class=FileHandler
level=DEBUG
formatter=arg0Formatter
args=('/var/log/cloud-init.log',)
- &log_syslog |
[handler_cloudLogHandler]
class=handlers.SysLogHandler
level=DEBUG
formatter=simpleFormatter
args=("/dev/log", handlers.SysLogHandler.LOG_USER)
log_cfgs:
# Array entries in this list will be joined into a string
# that defines the configuration.
#
# If you want logs to go to syslog, uncomment the following line.
# - [ *log_base, *log_syslog ]
#
# The default behavior is to just log to a file.
# This mechanism that does not depend on a system service to operate.
- [ *log_base, *log_file ]
# A file path can also be used.
# - /etc/log.conf
# This tells cloud-init to redirect its stdout and stderr to
# 'tee -a /var/log/cloud-init-output.log' so the user can see output
# there without needing to look on the console.
output: {all: '| tee -a /var/log/cloud-init-output.log'}
2.4.4. The /var/lib/cloud directory layout 复制链接链接已复制到粘贴板!
When cloud-init initiates, it creates a directory layout with instance details and cloud-init configuration. This directory can include optional directories, such as /scripts/vendor. The following is a sample directory layout for cloud-init:
/var/lib/cloud/
- data/
- instance-id
- previous-instance-id
- previous-datasource
- previous-hostname
- result.json
- set-hostname
- status.json
- handlers/
- instance
- boot-finished
- cloud-config.txt
- datasource
- handlers/
- obj.pkl
- scripts/
- sem/
- user-data.txt
- user-data.txt.i
- vendor-data.txt
- vendor-data.txt.i
- instances/
f111ee00-0a4a-4eea-9c17-3fa164739c55/
- boot-finished
- cloud-config.txt
- datasource
- handlers/
- obj.pkl
- scripts/
- sem/
- user-data.txt
- user-data.txt.i
- vendor-data.txt
- vendor-data.txt.i
- scripts/
- per-boot/
- per-instance/
- per-once/
- vendor/
- seed/
- sem/
- config_scripts_per_once.once