[09:29] <DanyC> hi all, anyone has any tips/ thoughts as to why cloud-init wouldn't run on a new EC2 instance created from an AMI which was created from a running EC2 instance? Pls not before creating the image i've run "cloud-init clean" to let cloud-init know/ think that is a first boot
[10:44] <meena> DanyC: and it didn't believe you… hrm…
[10:44] <meena> DanyC: cloudinit started on boot? what's /var/run/cloud-init look like? what do the logs say?
[10:48] <DanyC> meena: yes cloudinit started on boot. nothing odd in cloud-init.log while in -init-output.log it doesn't show me my user-data script
[10:52] <meena> DanyC: so what happens when you do a cloud-init clean --logs --reboot now?
[10:59] <DanyC> meena: same thing, i don't see any chance in init-output nor in the configuration of the instance.
[11:00] <meena> DanyC: any chance of/for what?
[11:00] <meena> oh, change.
[11:00] <DanyC> in short i have the same issue described (maybe better than me here) at https://www.reddit.com/r/aws/comments/bwfvtz/when_does_user_data_run_in_ec2_instances_whose/
[11:00] <DanyC> *change sorry for typo meena
[11:00] <meena> DanyC: at the very least, your hostname should have been set.
[11:06] <meena> n.b.: I have been lucky enough to have never worked with AWS. so take everything i say with a bag of salt.
[11:06] <meena> (i have worked with Salt however)
[11:27] <ananke> DanyC: interesting, I'll have to test this when I get to the office. I'm working now on a project involving that exact scenario: creating new AMIs from existing ones with packer. cloud-init does run in the results, but I haven't tested if user-data can be passed
[11:28] <DanyC> ananke: let me know your findings. Is a bit hit and miss on my side: as 2 our of 10 works. I've even tried to set/ do https://aws.amazon.com/premiumsupport/knowledge-center/execute-user-data-ec2/ but no luck
[11:44] <ananke> will do. I'll be in the office in a couple of hours, and I'll get to that first. this potentially means I'll have to bake in some cloud-init cleanup at the end of baking the image with packer
[11:45] <ananke> DanyC: what distros are you testing this with? I can check on amazon linux 2, centos 7, & ubuntu 18.04 lts
[11:48] <DanyC> ubuntu 16.04 ananke
[11:48] <ananke> didn't that reach EOL last year?
[11:49] <ananke> ahh, nevermind, studio did. 16.04 lts is still in maintenance update phase until 2021
[11:56] <DanyC> ananke: happy to provide the cloud-init version if that helps.
[11:57] <ananke> DanyC: how are you creating those AMIs? packer or some other process?
[11:59] <DanyC> ananke: custom, i create a vmdk from an iso using qemu and then import the main AMI. Then at T1 create new instance from the main AMI (cloud-init user data kicks in), do some manual config, run "cloud-init clean", then create image from the running EC2 (w/o reboot btw).  Then at T2 i create a new EC2 from the snapshotted AMI, userdata doesn't kick in
[12:00] <ananke> sounds like packer could help you automate that
[13:54] <DanyC> ananke: it could but that won't solve my prob. (there is more tech debt i need to tackle to get it going).
[13:57] <ananke> DanyC: btw, how do you pass your user-data to that new instance? using aws cli, their web console, or something else?
[14:00] <DanyC> ananke: through cfn, creating a basic EC2 instance and passing a bash script to it. Note i'm not using cfn-hup/ cfn-init etc, keep it dead simple
[14:02] <ananke> DanyC: and you're using the base64 encoding function right?
[14:02] <ananke> something like:       UserData:
[14:02] <ananke>         Fn::Base64: !Sub |
[14:02] <DanyC> ananke: that is correct, that is what i'm doing
[14:03] <ananke> that's actually on my to-do list this week, to have a new cloud formation template for testing the AMIs I create, including sending user-data. right now I just have the cloudformation template surrounding the packer creation
[15:36] <Odd_Bloke> DanyC: Could you file a bug and attach the tarball that `cloud-init collect-logs` creates on an affected instance, please?
[15:37] <Odd_Bloke> (File a bug at https://bugs.launchpad.net/cloud-init/+filebug :)
[16:23] <DanyC> Odd_Bloke: sure thing i can do so
[20:04] <ahosmanMSFT> @rharper I tried your suggestion and it should work in theory, but I get
[20:04] <ahosmanMSFT> type object 'PlatformComponent' has no attribute 'preserve_instance'
[20:04] <ahosmanMSFT> https://paste.ubuntu.com/p/KTSXVh5TRy/
[20:04] <rharper> ahosmanMSFT: yes, I was going to reply
[20:04] <rharper> you cannot reference a property of the definition
[20:04] <rharper> the object gets an instance in collect where it creates a PlatformComponent
[20:05] <rharper> in collect_snapshot IIRC
[20:05] <rharper> somewhere from the args.preserve_instance where that value is known, we'll need to propigate that through to the platform
[20:06] <rharper> possibly through the instance constructor; I was thinking it could be set in the config which is passed into the Image creation, but I'm not quite sure yet
[20:06] <ahosmanMSFT> rharper: I'll target the source then and pull the property from there instead