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-init has run
  • Examining log files
  • Finding templates

Depending on your requirement and datasource, there can be additional files and directories important to your configuration.

Expand
表 2.1. cloud-init directories and files
Directory or FileDescription

/etc/cloud/cloud.cfg

The cloud.cfg file includes the basic cloud-init configuration and lets you know in what phase each module runs.

/etc/cloud/cloud.cfg.d

The cloud.cfg.d directory is where you can add additional directives for cloud-init.

/var/lib/cloud

When cloud-init runs, it creates a directory layout under /var/lib/cloud. The layout includes directories and files that give specifics on your instance configuration.

/usr/share/doc/cloud-init/examples

The examples directory includes multiple examples. You can use them to help model your own directives.

/etc/cloud/templates

This directory includes templates that you can enable in cloud-init for certain scenarios. The templates provide direction for enabling.

/var/log/cloud-init.log

The cloud-init.log file provides log information helpful for debugging.

/run/cloud-init

The /run/cloud-init directory includes logged information about your datasource and the ds-identify script.

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-init phases, you must configure each module individually and list them in the cloud.cfg file. Modules run in the order given in cloud.cfg. You typically do not change this order. However, you can add additional modules to cloud.cfg, if Red Hat supports the modules that you want to add.
  • The cloud.cfg directives can be overridden by user data. When running cloud-init manually, you can override cloud.cfg with 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
  • users specifies the default user for the system. For more information, see Users and Groups.
  • disable_root enables or disables root login. For more information, see Authorized Keys.
  • ssh_pwauth specifies whether ssh is configured to accept password authentication. For more information, see Set Passwords.
  • mount_default_fields configures mount points. It must be a list containing six values. For more information, see Mounts.
  • ssh_deletekeys specifies whether to remove default host SSH keys. For more information, see Host Keys.
  • ssh_genkeytypes specifies key types to generate. For more information, see Host Keys.
  • syslog_fix_perms configures cloud-init to log all boot stages to its log file. For more information, see the cloud-config.txt file in the usr/share/doc/cloud-init/examples directory.
  • disable_vmware_customization enables or disables VMware vSphere customization.
  • cloud_init_modules: The modules in this section are services that run when the cloud-init service starts, early in the boot process.
  • cloud_config_modules: These modules run during cloud-init configuration, after initial boot.
  • cloud_final_modules: These modules run in the final phase of cloud-init, after the configuration finishes.
  • default_user specifies details about the default user. For more information. see Users and Groups.
  • distro: specifies the distribution.
  • cloud_dir specifies the main directory that contains cloud-init-specific subdirectories. For more information, see Directory layout.
  • templates_dir specifies where templates are located.
  • ssh_svcname is 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
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部