/srv/irclogs.ubuntu.com/2018/02/20/#cloud-init.txt

sidx64Hello! I'm new to cloud-init and I am using this with an openstack set up, to run some commands (create a specific user, etc) after VM is created. I was wondering if there was a way to run Cloud-init on the same VM without rebooting it ?14:13
sidx64never mind, I found it here: https://gist.github.com/maoueh/8662b8e0da0ccd99296a9a9a6b67dad014:48
=== rharper` is now known as rharper
brunobro_I'm trying to find a good pattern for using cloud-init to provision Raspberry Pi devices.15:26
brunobro_I found that the Raspbian repo had 0.7.9 and that lacked the more in depth NoCloud features. So, I figured out how to install from source. https://stackoverflow.com/a/48845732/11747115:36
brunobro_So at this point I'm trying to use /var/lib/cloud/seed/nocloud-net/ because it is pretty easy to get some positive feedback. But, I'm struggling to get the solution I need.15:42
brunobro_I really have 2 goals:15:42
brunobro_1. Have the `user-data` and `meta-data` files live on the volume labeled `boot` that is mounted at `/boot`15:44
brunobro_2. Have a script (/boot/on_boot.sh) called on every boot if it exists.15:45
brunobro_That's it. But, I'm facing these challenges:15:46
brunobro_1. /var/lib/cloud/scripts/per-boot seems to do nothing for me.15:47
brunobro_2. Changes to `/boot/user-data` are not picked up by the `#include` directive in `/var/lib/cloud/seed/nocloud-net/user-data`15:48
brunobro_3. The `meta-data` file does not seem to support `#include` so I'm stuck with whatever goes into `/var/lib/cloud/seed/nocloud-net/meta-data`15:56
brunobro_4. Putting ` ds=nocloud[;seedfrom=/boot/;instance-id=raspberrypi]` at the end of `/boot/cmdline.txt` did not seem to make it locate `/boot/user-data` and `/boot/meta-data`. That is why I am using `/var/lib/cloud/seed/nocloud-net/`.15:59
brunobro_I think that covers it.15:59
rharperbrunobro_: can you share your cloud-init.log ? /var/log/cloud-init*.log16:19
blackboxswsidx64: on cloud-init v 17.1 or later you can run "cloud-init clean --logs"   instead of those rm -rf lines. Also it'd be worth checking your initially provisioned datasource name in /run/cloud-init/result.json.  If it is a datasource with Local in the name you might have to run "cloud-init init --local" before "cloud-init init"16:22
sidx64thankyou @blackboxsw16:23
sidx64will tryu this16:23
blackboxswno prob: otherwise you risk using a cached local datasource which wouldn't update metadata (if your metadata has changed)16:24
sidx64Oh okay!16:25
sidx64Did not know that!16:25
sidx64I actually have been changing the metadata16:25
sidx64so this helps a lot!16:25
sidx64thank you16:25
rharperbrunobro_: you may want to instead label your  volume 'cidata';  and cloud-init will find that volume and read it like the nocloud-net seed in /var/lib/cloud/seed/noncloud-net instead16:26
brunobro_rharper: I can't relabel the volume. It is the boot volume. I'm not going to try to convince the Raspbian distribution to change their volume name. But, there is supposed to be a way to tell cloud-init somewhere else to look.17:02
rharperbrunobro_: ok17:02
rharperbrunobro_:  so, no wait to tell cloud-init to find a nocloud-net datasource somewhere else; but in the embedded seed, you should be able to refer to your volume for additional sources of user-data17:03
rharpers/wait/way17:03
brunobro_rharper: I added logs to https://gist.github.com/RichardBronosky/fa7d4db13bab3fbb8d9e0fff7ea88aa217:07
rharperthx17:08
brunobro_what can I do about per-boot?17:14
rharperbrunobro_: looking at the logs;17:23
rharperbrunobro_: from the logs, I think it's not finding your nocloud seed in /boot;  it emits the "Using Fallback Datasource" which isn't going to run your user-data that was provided;17:36
rharpernext to see why the seedfrom=/boot didn't work for you17:36
rharperI need to look at the cloud-init NoCloud source to see how it processes that17:36
brunobro_rharper: What should a "nocloud seed" in /boot look like? I never can get clear info on the directory structure expectations.17:40
brunobro_http://cloudinit.readthedocs.io/en/latest/topics/dir_layout.html says that "seed/" is TBD and "scripts/" is also pretty vague.17:42
rharperbrunobro_: /boot/{meta-data,user-data} ; I think you've that part correct;17:45
brunobro_okay, good. I originally did /var/lib/cloud/seed/{meta-data,user-data} and that did not work. But I found a blog example that told me about nocloud-net17:47
rharperso, it's /var/lib/cloud/seed/nocloud-net/{user-data, meta-data}17:47
rharperand you may have something in there; the stacktrace looks like it was comparing the instance_id found in one of the two meta-data files, and they didn't match;17:48
brunobro_I do have both of those populated.17:48
rharperI've never tested having multiple locations and referencing them both17:49
rharperso I suspect we need to pick one location and getting your config working17:49
rharperI think if you remove /var/lib/cloud/seed/nocloud-net and then 'cloud-init clean' to remove any per-instance generated data from /var/lib/cloud and logs; and reboot; that should get things goign if your gist is accurate17:52
brunobro_I don't intend to have multiple. I'm experimenting. And not remembering what artifacts I've left around.17:52
rharperthe seedfrom=/boot allows nocloud datasource to read that directory like it's a nocloud source; your files look fine w.r.t meta-data and user-data;17:53
rharperif that works, then we can move to getting your scripts to run;17:53
rharperI'm stepping out for lunch, but just let me know how it goes and I'll see what I can do to get your going17:53
brunobro_thanks!17:53
brunobronoskyrharper this is brunobro_ from earlier. (I didn't have a ZNC container running before.)19:40
rharperbrunobronosky: hi19:40
brunobronoskyI'm updating that gist to make it more accurate. i will also purge the logs and start them fresh. I'll let update you shortly. But for now I'll lead with a question...19:41
brunobronoskyIn the log I'm seeing "2018-02-20 18:05:39,432 - main.py[DEBUG]: No kernel command line url found." even though `cat /proc/cmdline` gives...19:44
brunobronosky8250.nr_uarts=0 bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2708_fb.fbswap=1 vc_mem.mem_base=0x3ec00000 vc_mem.mem_size=0x40000000  dwc_otg.lpm_enable=0 console=ttyS0,115200 console=tty1 root=PARTUUID=3e8f7ed9-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait ds=nocloud[;seedfrom=/boot/;instance-id=iid-raspberrypi-nocloud]19:44
rharperbrunobronosky: lemme look19:45
brunobronoskythat last KV pair is my interpretation of the docs http://cloudinit.readthedocs.io/en/latest/topics/datasources/nocloud.html19:45
rharperbrunobronosky:  I don't think that is related, the code is looking for  'cloud-config-url', 'url'  keys in the kernel command line for19:47
rharperit's used in a read-only-root configuration with MAAS, a baremetal cloud product19:48
rharperbrunobronosky: you should see something like19:49
rharperLooking for data source in: ['NoCloud', 'None'], via packages ['', 'cloudinit.sources'] that matches dependencies ['FILESYSTEM']19:49
rharper2018-02-15 16:23:32,828 - __init__.py[DEBUG]: Searching for local data source in: ['DataSourceNoCloud']19:49
rharper2018-02-15 16:23:32,828 - handlers.py[DEBUG]: start: init-local/search-NoCloud: searching for local data from DataSourceNoCloud19:49
brunobronoskyThe use of "url" concerns me. Can it accept a local file path? (maybe with the file:// scheme?)19:52
brunobronoskyOkay rharper https://gist.github.com/RichardBronosky/fa7d4db13bab3fbb8d9e0fff7ea88aa2#file-cloud-init-log is current.20:11
rharperbrunobronosky: thanks, reading20:12
brunobronoskyAlso, I'm seeing https://github.com/cloud-init/cloud-init/blob/master/doc/sources/kernel-cmdline.txt is consistent with your description. Though, both you and smoser are inconsistent with my understanding of http://cloudinit.readthedocs.io/en/latest/topics/datasources/nocloud.html20:14
brunobronoskyI didn't want to trouble you with my lack of understanding when you said, "I don't think that is related" earlier. I think that is more important than I originally presumed. I guess my follow up should be "You don't think what is related to what?"20:17
rharperthe message comes code looking for cloud-config-url, which is used separately from the NoCloud Datasource,20:17
rharperit's not related to the current failure20:17
brunobronoskyGot it. So, the part of the docs that I am hanging onto... Are they valid? Does that mean what I think it means? Inigo Montoya?20:21
rharperI think so, I'm looking at cloudinit/sources/DatasourcesNoCloud.py:parse_cmdline_data20:21
rharperto see what, if anything it doesn't like20:21
rharperI think the brackets20:24
rharper[ ] means the contents are optional20:25
rharperyou can use: ds=nocloud   or ds=nocloud;seedfrom=;instance-id=bar20:25
rharperadjusting it20:25
brunobronoskyGAH!!20:25
rharperparse_cmdline_data('ds=nocloud', fill, cmdline=cmdline)20:25
rharperTrue20:25
rharper>>> fill20:25
rharper{'instance-id': 'iid-raspberrypi-nocloud', 'seedfrom': '/boot/'}20:25
rharperbrunobronosky: I think it's worth an update to documentation to show an example there20:26
brunobronoskyYes! Moar Examples everywhere!20:26
rharper=)20:27
brunobronoskywoohoo! it created /var/lib/cloud/instances/iid-raspberrypi-nocloud that time.20:32
rharper\o/20:32
brunobronoskyNow I'm wondering about this /var/lib/cloud/scripts/per-boot thing20:37
brunobronoskyfor one. I noticce that it gets wiped out on `cloud-init clean`20:38
rharperyes, clean wipes the system to make it like "new" to cloud-init20:41
rharperright, per-boot;20:45
brunobronoskyholy carp! per-boot is working now.20:46
=== r-daneel_ is now known as r-daneel
brunobronoskyThis is working pretty smooth. I've got per-boot working as a symlink to /boot/per-boot.sh21:39
brunobronoskyNow I need some design advice.21:40
brunobronoskyI guess I should describe the greater project at this point. I'll try to keep it short.21:40
brunobronoskyIn 6 days, this project will be 5 years old! https://www.raspberrypi.org/forums/viewtopic.php?t=35224 The basic goal is to have a script in the vfat /boot partition of a newly imaged Raspbian microSD card that will get run on boot.21:49
brunobronoskyI've done this lots of ways over the years (mostly using rc.local) building dozens of single purpose machines.21:50
brunobronoskyMy projects have been forked and reused and I'm feeling kind of bad about spreading bad habits. I've decided finally do it right and get it accepted into Raspbian. My options were to create my own oneshot systemd service, or use cloud-init. I'd like to keep it as Standardâ„¢ as possible. So, I'm leaning towards this.21:53
blackboxswwell you're in good company here :) it's right in cloud-init's wheelhouse21:56
brunobronoskySome other users have expanded my original intent to have both an "on-boot.sh" and a "run-once.sh". Both of them get run if they are present, but the later gets renamed run-once.$(date +%F@%H.%M.%S) after execution.21:57
brunobronoskySo here is the design question (finally): implementing my on-boot.sh with /var/lib/cloud/scripts/per-boot is pretty simple. Should I try to implement run-once.sh with /var/lib/cloud/scripts/per-once or stray from the cloud-init Standardâ„¢ for that?21:59
brunobronoskymy meaning of per-once is "per once, every time it reappears", and cloud-init's meaning of per-once is "per once, ever, dammit". (at least from what I can tell)22:02
blackboxswbrunobronosky: I'm wondering why not per-instance instead of per-boot? per-boot is every boot22:02
blackboxswper-instance would only fire again if your NoCloud seed directories provide a different instance-id22:04
blackboxswand it wouldn't fire again across reboots22:04
blackboxswunless that data changed22:04
blackboxswor per-once might actually be what you need right, sorry because you only want to do that once ever22:07
blackboxswas long as your workflow never runs "cloud-init clean"  per-once scripts will never fire again after that first boot22:08
brunobronoskySo, the target audience for this is students and teachers. I'm trying to both make it easy and teach good practices... fine line. I want there to a script that runs on every boot, because a LOT of users want that.22:09
brunobronoskyThe per-instance is interesting. I didn't know the difference between per-once and per-instance. that gives me something to think about.22:10
brunobronoskyAnd yes, the per-boot is basically like rc.local, and that is the point. The difference is that a Windows (or Mac) user can mount the vfat partition and edit files in the /boot folder, but they cannot get to /etc.22:12
blackboxswif you don't expect metadata in the seed directory to change between boots when provisioning, per-instance effectively behaves like per-once.22:13
blackboxswyeah per-boot is probably what most folks would want;  in their own per-boot script they'd be able to change behavior to only perform an operation once if they want to.22:14
blackboxswwell, it least if gives the most flexibility I suppose.22:14
brunobronoskySo, is it terrible of me to use the names /boot/per-boot.sh and /boot/per-once.sh even though my per-once is totally different? Am I doing the student a disservice?22:18
brunobronoskyI just really like the consistency of the per-* and that they will sort together for the student to find.22:19
rharperbrunobronosky: it could be useful to bikeshed a name for per-every-occurance.sh or something22:20
rharperI do think the per-once (and only once per instance) is pretty straightfoward in the cloud-init space; though I think outside of cloud-init , the 'instance' concept is not quite as clear22:20
brunobronoskyrharper yes, instance is totally unclear outside of the cloud paradigm.22:24
brunobronoskyI'd love to have rpi clusters be a gateway for teaching cloud concepts... but that is a big bite for a beginner.22:25
rharperbrunobronosky: it may be useful then to include a script in your per-boot.sh which does an existance check on some directory, and if present call run-parts on it;22:26
rharperso you can tell users, if they create a directory named something your per-boot checks, it'll then call run-parts on it (which just executes any scripts/programs marked executable )22:27
brunobronoskynice!22:27
brunobronosky(eveything is executable on vfat)22:28
brunobronoskywell, mount mask 0022 so...22:31
=== brunobronosky is now known as brunobron-afk
rharperbrunobron-afk: lol @ vfat22:47

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