amazonlinux / amazon-linux-2023

Amazon Linux 2023
https://aws.amazon.com/linux/amazon-linux-2023/
Other
531 stars 40 forks source link

[Bug] - Cloud-Config user-data to power off not running #304

Open petercooperjr opened 1 year ago

petercooperjr commented 1 year ago

Describe the bug A directive given in cloud-config user-data to poweroff after cloud-config data runs doesn't seem to do anything in Amazon Linux 2023, though the same user-data works on Amazon Linux 2.

To Reproduce Testing done in the us-east-1 region.

Create a file power-off.cloud-config with these contents:

#cloud-config
power_state:
  delay: now
  mode: poweroff

Start an instance using that file as user-data:

aws ec2 run-instances --image-id resolve:ssm:/aws/service/ami-amazon-linux-latest/al2023-ami-minimal-kernel-default-arm64 --instance-type t4g.nano --instance-initiated-shutdown-behavior terminate --user-data file://power-off.cloud-config

The instance launches, but does not turn off and terminate on its own as directed.

Expected behavior If doing the same thing with Amazon Linux 2, the instance does shut itself down and terminate after running the cloud-config data:

aws ec2 run-instances --image-id resolve:ssm:/aws/service/ami-amazon-linux-latest/amzn2-ami-minimal-hvm-arm64-ebs --instance-type t4g.nano --instance-initiated-shutdown-behavior terminate --user-data file://power-off.cloud-config

Additional context Obviously my actual case is a cloud-config with more commands to run on bootup and then having the instance terminate itself after running them; this is just a minimal example to reproduce the problem.

nmeyerhans commented 1 year ago

I can confirm this behavior. For now, you can work around the problem by adding a condition that evaluates to true, so the following cloud-config will do what you expect:

#cloud-config
power_state:
  delay: now
  mode: poweroff
  condition: /bin/true
diablodale commented 4 months ago

Another fail of the power_state.

power_state:
 condition: '! needs-restarting -r'
 message: Rebooting for upgrade
 mode: reboot

A few years ago this would always reboot the server. But now this does not reboot. Yet I know that condition should trigger, and when I console to the instance and run the condition it returns true.

Related the a needed cloud init module not loaded? https://bugzilla.redhat.com/show_bug.cgi?id=1252477