/srv/irclogs.ubuntu.com/2024/07/19/#cloud-init.txt

caribouHello aciba, I just saw your comment on GH#5523 and added a reply. Let me know if you want to discuss it further11:33
acibacaribou: thanks for the ping, I think it is okay for the moment!15:42
hwrdhello, I'm trying to figure out why my cloud-init script didnt fully run on Amazon Linux 2023. It's getting set up via Terraform, and so I cnt find the config filethe machine17:30
hwrdit's not in /etc/cloud/cloud.cfg.d/, nor does /var/lib/cloud/instance/user-data.txt exit17:31
hwrdexist*17:31
hwrdI'm able to `ssh` intothe machine, which means part of my cloudinit script ran (to create my user and set authorized_keys), but the end ofthe script didnt create directories I expected17:32
hwrdlooks like it's just my runcmd tht's not working18:01
blackboxsw@hwrd sorry for the delay here. You can check quickly if cloudinit has errors given one of the following commands: `cloud-init status --format-yaml`   (will show you warnings or errors with potenital user-data or scripts).       And `sudo cloud-init query userdata` (to see the user-data that cloud-init was provided by your cloud at launch).    19:43
blackboxsw@hwrd and finally: `sudo cloud-init schema --system --annotate`  (to tell you about invalid user-data schema)19:43
blackboxswhwrd: If there were errors in your runcmd script, some of the stdout stderr may be redirected to /var/log/cloud-init-output.log so watch for script errors there19:43
blackboxswtypo correction: `cloud-init status --format=yaml`  19:44
hwrdyeah so this `sudo cloud-init schema --system --annotate` tells me that `var/lib/cloud/instance/user-data.txt` doesn't exist, which is true.19:54
hwrdand `cloud-init status --format=yaml` tells me `/usr/bin/cloud-init: error: unrecognized arguments: --format=yaml`19:55
hwrdwithout `--format=yaml` it just says `status: done`19:55
hwrdI think it may be this https://www.virtualthoughts.co.uk/2023/01/18/debugging-cloud-init-not-executing-runcmd-commands/19:55
hwrdI've rebuilt my packer image, about to stand up an instance now.19:56
hwrdwhat's puzzling to me is, I don't know where my config is on the machine, if it's not at `/var/lib/cloud/instance/user-data.txt`. In fact `/var/lib/cloud/instance` doesn't even exist19:57
hwrd`sudo cloud-init query userdata` returns empty blackboxsw20:03
hwrd`sudo cloud-init schema --system --annotate` tells me `FileNotFoundError: [Errno 2] No such file or directory: '/var/lib/cloud/instance/user-data.txt'`20:04
hwrdright, so cloud-init-config.service wasn't the issue.20:05
hwrd`/var/log/cloud-init-output.log` doesn't have any of my custom cloudinit config. the only thing tht stands out is, `2024-07-19 19:58:07,522 - schema.py[WARNING]: Invalid cloud-config provided: Please run 'sudo cloud-init schema --system' to see the schema errors.`, which as I mentioned, just tells me that `FileNotFoundError: [Errno 2] No such file or directory: '/var/lib/cloud/instance/user-data.txt`20:07
hwrdbut, it looks like my cloudinit IS running, as all the files are there... but nothing in `runcmd` is running... but `bootcmd` is.20:07
minimalhwrd: which DataSource are you using?20:09
hwrdminimal: wht does DataSource mean?20:09
blackboxswgiven that you have no runcmd userdata provided to the current launch of the machine, cloud-init optimizes and ignores certain modules because no current user-data has a runcmd key that requires cloud-init to interact20:09
blackboxswdatasource == target cloud platform20:09
minimalwhere cloud-init gets meta-data/network-config/user-data from20:09
hwrdAWS. I'm upgrading our AMI from Amazon Linux 2 to Amazon Linux 202320:09
hwrdno code has changed for userdata20:10
minimalAMI? ok, so likely using Ec2 DataSource20:10
minimalassuming you're running in AWS rather than running Amazon Linux on a local hypervisor20:10
hwrdprobably. I'm doing it thru https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance#user_data20:11
hwrdthis exact same user_data works on Amazon Linux 2... but doesn't seem to on Amazon Linux 202320:12
hwrdit looks like everything besides `runcmd` is being run... but I don't see any traces of anything being run in the logs20:12
blackboxswhwrd: so the reason you see bootcmd run but not runcmd is because bootcmd module is special and runs PER_ALWAYS, runcmd only runs when user-data containing a `runcmd:` key is presented to the instance at first launch. When cloud-init doesn't see certain top-level config keys in user-data it'll skip running that module because there's nothing to do and you see logs like the following:20:12
blackboxsw2024-07-18 12:11:17,344 - modules.py[INFO]: Skipping modules 'wireguard,snap,ubuntu_autoinstall,keyboard,apt_pipelining,ubuntu_pro,ntp,timezone,disable_ec2_metadata,runcmd' because no applicable config is provided.20:12
minimalcan you clarify if you're running in AWS rather than running Amazon Linux on a local hypervisor?20:13
hwrdblackboxsw my user-data does contain `runcmd` though.20:13
hwrdminimal: yes, running in AWS20:13
blackboxswhrwd: I'm confused as you also said above "`sudo cloud-init query userdata` returns empty blackboxsw" which on the target system shows there was no user-data provided to the VM launched in ec220:14
hwrdblackboxsw that's confusing to me too20:14
hwrdbecaue20:14
blackboxswI think you are providing user-data to terraform, builds, but not user-data to the target platform you are deploying?20:15
minimal"this exact same user_data works on Amazon Linux 2... but doesn't seem to on Amazon Linux 2023" - from memory AL2 contained a old and heavily modified (by AWS) cloud-init whereas AL2023 is "closer" (i.e. less modified) to mainstream cloud-init20:15
blackboxswahh, hrm20:15
hwrdblackboxsw it's getting there somehow, but not in the normal locations...20:15
hwrdi.e, it's not at /var/lib/cloud/instance20:16
hwrdfor example, I hve ```write_files:  - path: /usr/local/sbin/ec2-hostname.sh'`20:16
hwrdand tht file exists on the instance20:16
hwrdand all my `users:` are there too20:17
hwrdbut I cnt find where the userdata file is on the machine.20:17
hwrdmight userdata be somewhere besides /var/lib/cloud/instance/user-data.txt?20:18
hwrdminimal are you sure tht's not the other way around? cuz I can't find anything in the canonical locations on AL202320:18
minimalcloud-init.log should have an entry like "util.py[DEBUG]: Writing to /var/lib/cloud/instances/< uuid >/user-data.txt"20:20
hwrdlemme check20:20
minimalas /var/lib/cloud/instance is generally a softlink to a /var/lib/cloud/instances/< uuid > directory20:21
hwrdminimal: nothing https://gist.github.com/hahuang65/53cd8a9531b5110b84a8524f6cc6e14920:22
hwrdweird20:23
hwrdso /var/lib/cloud/instances/i-051c0d43e54061fd9/ only has a directory `sem`20:23
minimalDataSourceNone...20:23
minimalrather than Ec220:23
minimal"Used fallback datasource"20:24
hwrdwhat would be fallback datasource?20:24
hwrdfrom my perspective, the userdata is DEFINITELY running20:25
hwrd`+ '[' '!' -f /root/cloud-init-ebs-mounted ']'` this line, is from my userdata20:25
hwrdall my scripts and files are place. Users and their `.ssh/authorized_keys` are all there20:26
blackboxswwhoa, cloud-init 22.2.2 that is ooooold.20:26
hwrdblackboxsw maybe I need to update it. weird that's what AL2023 ships with.20:26
blackboxswok so there will definitely be some feature differences in this image when comparied to tip of main.20:26
hwrdhttps://docs.aws.amazon.com/linux/al2023/ug/al2023-ami-kvm-image.html20:27
blackboxswyeah different distro downstreams grab upstream releases of cloud-init at different paces. And some of those downstreams have custom patches that may prevent you from grabbing latest20:27
minimalblackboxsw: it is AL 2023 though ;-)20:27
hwrd22.2.2.. that's wht it ships with.20:27
blackboxswright :)20:27
minimal23.2.2 is from July 202320:27
blackboxsw22 is a year prior, but yeah close enough. the version isn't really the problem here it's something in how the config is being handled. and that fallback datasource indicated it couldn't connect to Ec2 properly20:28
hwrdlol so, Cloud-init v. 19.3-46.amzn2.0.1 works with my userdata20:28
blackboxswand fell back to a basic/defaul config20:28
minimalI'm assuming that the c-i version in AL2 didn't have the same level of schema validation20:29
hwrdblackboxsw tht's wht it looks like from the logs... but it is DEFINITELY running my userdata20:29
hwrdminimal I dont think the schema validtion is the issue. it's not even finding the user data file to validate20:29
minimalhwrd: so how then is it running your bootcmd (in the user-data) if it cannot find the user-data?20:30
blackboxswminimal: bootcmd runs always on every boot regardless of user-data present20:30
hwrdminimal: no idea... but shouldn't schema validation fail the entire file?20:30
hwrdmy question right now is... where the hell is my user-data.txt file20:30
minimalblackboxsw: I though the bootcmd was running the specific bootcmd values specified in his user-data20:31
hwrd`cloud-init` command expects it to be at `/var/lib/cloud`20:31
blackboxswahh sorry missed that part 20:31
hwrdminimal blackboxsw yes, bootcmd is running the specific bootcmd values in my user-data20:31
minimalhwrd: so did you check inside /var/lib/cloud/instances/ to see if uuid dir exists?20:31
hwrdyeah, lemme send tht over20:31
blackboxswhwrd: probably best if you can paste your full cloud-init log somewhere. Double check it doesn't have passwords exposed in logs20:32
blackboxswhttps://paste.opendev.org/ or something20:32
hwrdblackboxsw I did. it's here https://gist.github.com/hahuang65/53cd8a9531b5110b84a8524f6cc6e14920:33
blackboxswhwrd: I thought that was a snippet. your paste starts with `Cloud-init v. 22.2.2 running 'init' at Fri, 19 Jul 2024 19:01:56 +0000. Up 8.67 seconds.` which is the second boot stage of cloud-init20:33
minimalblackboxsw: looks like the cloud-init doesn't have debug enabled20:34
hwrdoh tht's `cloud-init-output.log`20:34
hwrddo you wnt `cloud-init.log`?20:34
minimalah, yes that's what we're after20:34
hwrdk20:34
blackboxswcorrect. `cloud-init analyze show` should also hopefuly confirm that your env has run 4 separate boot stages20:34
blackboxswif any of those 4 stages is skipped, cloud-init won't run all your config, or won't properly detect the datasource(ec2)20:35
hwrdhttps://gist.github.com/hahuang65/84aea524581f5dd5f6787d4ead75519720:35
minimalblackboxsw: <joke> don't you have some Windows boxes to fix? ;-)20:35
blackboxswtell me about it 20:35
blackboxsw#pay_no_attention_to_the_reviewer :)20:35
hwrdhere's the analyze https://gist.github.com/hahuang65/0f89e91f528717ee10da7c995b8e8db120:36
blackboxswhwrd: again that past starts with only `Cloud-init running 'init'` which makes me think we are skipping early detection stage. though I do see Cloud-init v. 22.2.2 running 'modules:config'  and `final` and minimal's comment of not being in DEBUG log levels hurts us here as we really can't see much at all20:37
hwrdbizarre... idk how to get those earlier stages20:38
blackboxswhwrd: are you sure that's /var/log/cloud-init.log ???? that really looks like cloud-init-output.log to me20:38
minimalyeah he mentioned that, am waiting for cloud-init.log20:38
hwrdhttps://gist.github.com/hahuang65/84aea524581f5dd5f6787d4ead755197 this should be `cloud-init.log`20:39
minimalalso "analyze" output mentions DataSourceEc2, not DataSourceNone20:39
hwrd`sudo head /var/log/cloud-init.log2024-07-19 19:01:56,185 - util.py[DEBUG]: Cloud-init v. 22.2.2 running 'init' at Fri, 19 Jul 2024 19:01:56 +0000. Up 8.67 seconds.2024-07-19 19:01:56,186 - main.py[DEBUG]: No kernel command line url found.2024-07-19 19:01:56,186 - main.py[DEBUG]: Closing stdin.`20:40
blackboxswanalyze also mentions runcmd too.20:40
hwrdpretty bizarre.20:40
blackboxsw2024-07-19 19:01:58,686 - cc_runcmd.py[DEBUG]: Skipping module named runcmd, no 'runcmd' key in configuration20:41
blackboxswyet user-data confirmed empty `2024-07-19 19:01:56,436 - url_helper.py[DEBUG]: Read from http://169.254.169.254:80/2021-03-23/user-data (200, 0b) after 1 attempts`20:42
blackboxsw0b20:42
hwrdbut what configuration is it reading20:42
hwrdif it's doing all the other stuff in my user-data20:42
blackboxswyeah strange20:43
hwrdso /var/lib/cloud/instances/ has i-051c0d43e54061fd9  iid-datasource-none20:43
hwrdboth only have `sem` directories. no `user-data.txt`20:43
minimalblackboxsw: wasn't there an issue in the past to do with user-data from some metadata servers (multi-part? compressed?) were it wasn't recognised20:45
hwrdtht sounds like it COULD be it20:46
hwrdor even this https://github.com/amazonlinux/amazon-linux-2023/issues/40120:46
-ubottu:#cloud-init- Issue 401 in amazonlinux/amazon-linux-2023 "[Bug] - Custom cloud init hack for userdata is broken for AL2023" [Closed]20:46
minimalc-i 23.3 "Ec2: support decoding souble base64 encoded user-data" 20:47
hwrdyeh in Terraform, I've got `  base64_encode = true`20:47
hwrdlemme try without it20:48
minimal#427620:48
minimalhwrd: that's the c-i fix for amazonlinux 40120:49
hwrdyeah I'm using the absolute latest amazonlinux 202320:49
hwrdbut worth a shot without base6420:49
hwrdthis is the last thing I can try for now. gotta go make dinner for the litte ones.20:51
blackboxswahh right, forgot about that PR/condition20:51
hwrdlooks to be the same issue.20:52
hwrddammit20:52
hwrdyeh still `2024-07-19 19:01:56,436 - url_helper.py[DEBUG]: Read from http://169.254.169.254:80/2021-03-23/user-data (200, 0b) after 1 attempts`20:54
blackboxswyeah, I need to disappear too. thx minimal for the recall  there on double compression which would have affected cloud-init 22.2 in that AL image being launched . since I'm not as familiar with terraform, nor amazonlinux setup, this makes things a bit more challenging to reason about. I'm still bugged by lack of an 'init-local' boot stage there too I would expect to see an init service trying to run that stage20:54
blackboxswone other thing in logs. `2024-07-19 19:01:56,853 - util.py[DEBUG]: Writing to /var/lib/cloud/instances/i-008c9917e10c667dc/user-data.txt.i - wb: [600] 308 bytes`20:54
hwrdblackboxsw minimal thanks so much for your help so far. I'll be back to poke t it20:55
blackboxswI'm seeing non-zero user-data.txt.i file written. I'm curious what that userdata first line is20:55
minimalhwrd: that "0b" (but 200 HTTP status code) seems to mean the user-data is just not there on the AWS's metadata server20:55
hwrdhrm20:55
blackboxswif it's not `#cloud-config` cloud-init would ignore it20:55
blackboxswand when processing it takes user-data.txt.i and writes out an empty user-data.txt file in that directory20:56
hwrd`sudo cat /var/lib/cloud/instances/i-008c9917e10c667dc/user-data.txtcat: /var/lib/cloud/instances/i-008c9917e10c667dc/user-data.txt: No such file or directory`20:56
hwrddoesnt exit20:56
hwrdexist*20:56
blackboxswwth :/20:56
hwrdlol right?20:56
minimalblackboxsw: I'm assume the "0b" actually means "zero bytes retrieved" rather than "zero *valid* bytes retrieved"20:56
blackboxsw-> stepping away (not to be confused with a rage quit ;) 20:56
blackboxswminimal: correct that's num bytes read/written20:56
hwrdblackboxsw :)20:57
hwrdI'll be back. thanks again guys20:57
minimalso if the metadata server doesn't provide any user-data to cloud-init then I'm not sure how it's a cloud-init problem20:57
blackboxswso it got non-empty, did something with it and didn't like format so userdata processing wrote out an empty user-data.txt file in that particular case20:57
blackboxswminimal: yes, or if the user-data provided by packer wasn't the right format for some reason and cloud-init silently ignored it, that's the only potential prob I see for cloud-init. So if possible can hwrd paste later a clean/safe version of the original user-data provided?20:58
blackboxswor on the target system with cloud-init run `cloud-init schema -c <your_user_data> --annotate`20:59
blackboxswit should tell you if the raw user-data being provided is bogus too for some reason (though cloud-init 22.2 may not have great schema support for --annotate)20:59
blackboxswit should tell you if the raw user-data being provided is bogus too for some reason (though cloud-init 22.2 may not have great schema support for --annotat)20:59
blackboxswit should tell you if the raw user-data being provided is bogus too for some reason (though cloud-init 22.2 may not have great schema support for --annotate)20:59
blackboxsw<- steps away21:00
minimalor was the user-data not in place on the IMDS in time? At 19:01:56 it is 0 bytes retrieved from IMDS, at 19:58:06 (2nd boot) it is 5326 bytes!21:00
=== blackboxsw is now known as blackboxsw_away
minimalsome async behaviour regarding VM creation and IMDS data population?21:00
hwrdbut for cloud-init schema -c <your_user_data> --annotate... I dont know what <your_user_data> is.. that file doesnt exit21:02
hwrdexist21:02
blackboxsw_awayhwrd: I mean cut-n-paste it into a file on a system with cloud-init installed21:03
blackboxsw_awaycloud-init -c my-file.yaml --annotate21:03
blackboxsw_awaycloud-init schema -c my-file.yaml --annotate21:03
hwrdah... hrm... I'm actually not sure how terraform stitches allthe parts together. I need to figure out if Terraform will output the entire file for me.21:03
hwrdor I can steal it from another machine.21:03
blackboxsw_awayor `lxc launch ubuntu-daily:noble test-n` to launch an ubuntu system which will have newer cloud-init installed21:04
blackboxsw_awayand could run cmds there with your file (if the AL virtual machine doesn't give you SSH)21:04
hwrdah it's base64 on this other system. I'll be bck tonight to untangle more21:07
hwrdwait no... it's not... ...why is `user-data.txt` some binary formt?21:08
minimalthe main question is why is user-data present on IMDS at 19:58:06 but not at 19:01:56 ?21:09
blackboxsw_awayyep21:14
blackboxsw_awayand whatever that fmt is it wasn't digested by cloud-init 22.2 (because PR 4276 landed in cloud-init 23.3 I think) to deal with that double compressed binary21:14
hwrdthen the double compressed isn't the issue then. this user-data was running on version 19 (Amazon Linux 2)21:19
hwrdminimal: it seems to have read it from IMDS the second go around... but didn't save it anywhere. 21:20
minimalhwrd: well generally the "important" cloud-init stuff happens on 1st boot21:55
minimalso user-data not being available then is not good21:55
hwrdhrm I gotta figure out why then21:59
hwrdbut actually if I curl it after... it's still empty. wonder why21:59
minimaldon't you need a "security" token to curl it?22:04

Generated by irclog2html.py 2.7 by Marius Gedminas - find it at mg.pov.lt!