Updated on 2024-03-05 GMT+08:00

Why Can't My ECS Use Cloud-init?

Symptom

An ECS is not able to use cloud-init.

Troubleshooting

Figure 1 shows the process for an ECS to obtain metadata using the cloud-init.
Figure 1 Process for obtaining metadata

Check the following possible causes.

Figure 2 Possible causes
Table 1 Possible causes

Possible Cause

Solution

The ECS has no IP address obtained.

See The ECS Has Not Obtained IP Address

Incorrect route for 169.254.169.254

See Incorrect Route for 169.254.169.254

Fail to obtain the ECS metadata.

See Did Not Obtain the ECS Metadata

Fail to log in to the ECS or create a non-root user after cloud-init is configured.

Check the format of the /etc/cloud/cloud.cfg configuration file. For details, see Cannot Log in to the ECS or Create a Non-root User After Cloud-init Is Configured.

Fail to use an obtained private key to log in to an ECS after the ECS starts (Fail to obtain the ECS login password).

Restart the ECS and try again.

The ECS Has Not Obtained IP Address

Check whether the ECS has obtained an IP address.

If no IP address is obtained, run the dhclient command to obtain the IP address (this command varies depending on the ECS OSs). Alternatively, you can run the ifdown ethx command to disable the network port and then run the ifup ethx command to enable it to allow the ECS NIC to automatically obtain an IP address again.

Figure 3 ECS IP address

Incorrect Route for 169.254.169.254

Ping 169.254.169.254/32 from the ECS. If the IP address cannot be pinged, perform the following steps:
  1. Check the exact route configured on the ECS for IP address 169.254.169.254/32.

    In most cases, the next hop of the exact route for IP address 169.254.169.254/32 is the same as that of the default route for the IP address.

    Figure 4 Route for IP address 169.254.169.254/32
  2. If there is no exact route for IP address 169.254.169.254/32, the cause is as follows:

    Images with CentOS 5 OSs are not compatible with cloud-init. To use cloud-init, select a different OS.

  3. If the next hop of the exact route for IP address 169.254.169.254/32 is different from that of the default route for the IP address:
    • If the ECS was created before cloud-init was enabled, run service network restart to obtain the correct route.

Did Not Obtain the ECS Metadata

Run the following command on the ECS to obtain the metadata:

curl http://169.254.169.254/openstack/latest/meta_data.json

If information similar to that shown in Figure 5 is displayed, the ECS successfully obtains the metadata.

Figure 5 Command output

Cannot Log in to the ECS or Create a Non-root User After Cloud-init Is Configured

Check whether the /etc/cloud/cloud.cfg configuration file format is correct. For details, see the file format requirements for different Linux distributions. The following figure shows an example /etc/cloud/cloud.cfg configuration file for Ubuntu.

Figure 6 Configuration file

Obtained Private Key Cannot Be Used to Log in to an ECS After the ECS Starts (Failed to Obtain the ECS Login Password)

Restart the ECS to rectify the fault.