2.3. Boot stages of cloud-init
The cloud-init utility completes VM configuration in the following 5 boot stages. Phase is the logical grouping of the boot stages that controls the sequence of execution of modules. The default modules execute in the specific phase.
During system boot, the cloud-init utility operates in five stages that determine whether cloud-init runs and where it finds its datasources, among other tasks. Each stage also belongs to a module execution phase, which controls what modules are run. The stages are as follows:
Detect stage: By using the
systemdservice, this stage determines whether to runcloud-initutility at the time of boot. Theds-identifytool detects whether or not to runcloud-initin the absence of a valid platform.This stage belongs to the Initialization phase and does not execute any modules. Instead, it identifies the datasource for
cloud-initconfiguration.Local stage:
cloud-initsearches local datasources and applies network configuration, including the DHCP-based fallback mechanism.This stage belongs to the Initialization phase and does not execute any modules.
Network stage:
cloud-initprocesses user data by running modules listed undercloud_init_modulesin the/etc/cloud/cloud.cfgfile. You can add, remove, enable, or disable modules in thecloud_init_modulessection.This stage belongs to the Networking module execution stage.
Config stage:
cloud-initruns modules listed undercloud_config_modulessection in the/etc/cloud/cloud.cfgfile. You can add, remove, enable, or disable modules in thecloud_config_modulessection.This stage belongs to the Configuration module execution phase.
Final stage:
cloud-initruns modules and configurations included in thecloud_final_modulessection of the/etc/cloud/cloud.cfgfile. It can include the installation of specific packages, as well as triggering configuration management plug-ins and user-defined scripts. You can add, remove, enable, or disable modules in thecloud_final_modulessection.This stage is equivalent to the Finalization module execution phase.
During the first boot of VM, when the cloud-init service initiates, all the configured modules execute in their respective phases. On subsequent booting, whether a module executes within a phase depends on the module frequency of that module. Module frequency is set in the cloud-init configuration, and determines whether a module executes every time cloud-init runs on the instance, or only the first time cloud-init runs, even if the instance ID changes.
An instance ID uniquely identifies an instance. When an instance ID changes, cloud-init treats the instance as a new instance. For details, see Scename definition for module creation.
The possible module frequency values are as follows:
-
PER_INSTANCEmeans that the module runs on first boot of an instance. For example, if you clone an instance or create a new instance from a saved image, the modules designated as per instance run again. -
ONCEmeans that the module runs only once. For example, if you clone an instance or create a new instance from a saved image, the modules designated per once do not run again on those instances. -
PER_ALWAYSmeans the module runs on every boot.
You can override a module’s frequency when you configure the module or by using the command line.