Score:0

Cloud-init doesn't run as first boot for instance launched from an AMI created from another instance

ru flag

We configure AWS EC2 instances (Ubuntu 20.04) with cloud-init using user-data scripts. We're noticing the user-data scripts don't execute if they are run on instance which is launched from a custom AMI created from another launched instance.

We create an intermediate AMI which has common tools & frameworks and reuse it for specific needs -

  1. First, we launch an instance from a published AMI. The user-data scripts get executed perfectly fine as first boot on this instance.
  2. We create an intermediate AMI from the instance launched in first step.
  3. Then launch another instance from the intermediate AMI.

We provide user-data script in the instance launched from intermediate AMI as well but somehow the script doesn't execute. I observed that the cloud-init's metadata crawler service (cloud-init.service) doesn't run in the step 3 and hence the user scripts are not executed.

We've already tried to clean the cloud-init cache before creating the intermediate AMI so that the cloud-init can run as first boot on the new instance [Reference] -

sudo cloud-init clean --logs --seed

And I've also tried to clean the /etc/machine-id as shared here but nothing works.

Is there anything I'm missing to clean for cloud-init so that it can run as first boot for new instances?

th flag
If cloud-init.service isn't running at all, that's a problem. Is something else on boot blocking it from running? Does systemctl list it as an enabled service? Does /var/log/cloud-init.log show it attempting to run?
guiverc avatar
cn flag
You mention both Ubuntu-20 (closest being Ubuntu Core 20 for cloud) & Ubuntu 20.04 (tagged); they are different products, so please be precise with details. 20 != 20.04 as the 20 or *year* format signifies a *snap* only product (no `apt` like commands exist) having existed since 2016.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.