[10:19] hi [10:22] i'm currently creating some custom images using packer to simplify my deployments. The idea is that the image would install apps from git repos using metadata provided to cloud-init by the cloud provider ot user [10:23] for that i would just need some script to run on per-instance; what would be the 'right' way to achieve that? [10:24] from the docs i see 2 possibilities: [10:26] add a script in .../scripts/ ; but as i get it, those scripts should be created from a module/part-handler, not 'simply exists' [10:27] create a custom module ; but as i get it, that would mean modify cloud-init sources and install that modified version [10:28] isn't there a way to simply say 'this cloud-init installation runs on per-instance"? [10:34] adding a custom module without the need for an installation from modified sources would be the ideal solution, can that be done? [10:42] targeted use case: automatically clone repositories, checkout a specific 'version', and run provisioning script. based on digitalocean tags set on the instance. ideally the script should run every time those tags changes, in order to uninstall 'disappeared' tags, and install new ones (but i can live with it running only on droplet creation) === domovoy_ is now known as domovoy [14:26] domovoy: making your own module would be a lot of work [14:28] domovoy: take a look at this module, it does what you want https://cloudinit.readthedocs.io/en/latest/reference/modules.html#runcmd [15:37] holmanb: runcmd would allow me to run a custom command, sure, but it still need to be setup from cloud or user data. or is there a way to make it so that it's part of the base config, no matter what is provided by cloud or user? [16:02] domovoy: aren't "run on per-instance" and "should run every time those tags change" contradictory? [16:07] minimal: not according to https://cloudinit.readthedocs.io/en/latest/development/module_creation.html [16:08] "PER_INSTANCE: Runs once per instance. When exactly this happens is dependent on the datasource, but may triggered any time there would be a significant change to the instance metadata. An example could be an instance being moved to a different subnet." [16:09] AFAIK per-instance refers to the instance id changing [16:10] which typically happens when cloud-init runs on 1st boot (or if you "clean up" cloud-init so that it runs again from fresh on next boot) [16:11] you'll see instance id's logged in /var/log/cloud-init.log and in /var/lib/cloud/cloud/instances/ [16:11] as i understand it, the datasource may also make it happen whenever it decides there are changes that warrant it, probably by changing the instance id actually [16:12] right, I did say "typically" earlier ;-) I'm not sure which datasources tend to change the instance id [16:13] me neither, which is why this "every time the tags change" part is considered the ideal case, and i said i'd be happy with it happening only on instance creation [16:13] if you want it to run every time have you looked at placing the script in /var/lib/cloud/scripts/per-boot/ ? [16:15] yeah, i've considered placing a scripts in the ...scripts/ directory, but the doc states "Scripts in one of these subdirectories are downloaded/created by the corresponding part-handler"; so placing "permanent" scripts there out the cloud-init process seems like it's not the "right" way [16:17] i could also create an init script which would query cloud-init metadata, there are actually many ways i could achieve my goal. my question is about what would be "normal, as thought by the devs, cloud-init way" [16:19] just tested by creating a simple shellscript in /var/lib/cloud/scripts/per-boot/ and making it executable, then rebooted, and it ran as expected [16:20] i know it works, still not my point, and from the doc, not the way those directories should be used [16:25] I think the docs are perhaps incorrect or misleading [16:25] wat makes you think that? [16:25] from a quick look at the source code of various DataSources the only one that makes reference to /var/lib/cloud/scripts is the SmartOS one [16:26] which refers to vendor-data being a boothook to write a script into per-boot [16:26] datasources maybe, but part handlers definitely write scripts there [16:28] https://cloudinit.readthedocs.io/en/latest/explanation/format.html#mime-multi-part-archive [16:31] that's referring to one of the formats of user-data [16:32] the mime-multipart format, which is handled by... part handlers [16:32] yes, when you provide mime-multipart format as the user-data [16:33] which, according to the doc, is what is supposed to put script is ...scripts/ subdirectories [16:33] "Scripts in one of these subdirectories are downloaded/created by the corresponding part-handler" [16:33] I wasn't referring to providing a per-boot script via user-data, I was referring to writing a script directly to /var/lib/cloud/scripts/per-boot/ as part of your Packer image creation [16:34] yes, and again, the doc says that's not how those directories are supposed to be used... [16:34] I'm saying that I *think* the docs are misleading and should instead say "Scripts in one of these subdirectories can be downloaded/created by the corresponding part-handler" [16:35] i haven't found nothing in the doc saying cloud-init is supposed to handle cases when a script is placed there out of its process, i only found indication of the opposite actually [16:35] and perhaps also explicitly say "or you can place scripts directly there during image creation" [16:35] that would indeed solve my problem [16:36] but unless confirmed otherwise, i can only believe the doc [16:36] you're assuming the docs are 100% correct and that anything not indicated by the docs are not permitted/intended....which may or may not be correct, I don't know, that's for one of the Canonical guys to comment on [16:36] i'm assuming nothing, hence me asking [16:36] best to ask on a week day as the Canonical guys don't tend to be around on weekends [16:42] just so that my request is clear for everyone: i'm asking how it _should_ be done, not how it _can_ be done. thanks [18:20] hmmm, although not stated explicitely, https://cloudinit.readthedocs.io/en/latest/reference/base_config_reference.html gives an example with a `users` setting, which would hint that those files can contain not only the keys listed on this page, but also modules configs [18:20] Is that accurate? [18:21] It would allow me to create a file in /etc/cloud/cloud.cfg.d/, which would include a `runcmd` command, and hence run my command the "cloud-init" way [18:23] as indicated at the top of that page this is the base configuration for cloud-init (i.e. where you define which modules it may attempt to run etc) [18:24] so you'll see "runcmd" mention in the example "cloud_config_modules:" section which indicates that the runcmd module should be run during the "config" cloud-init stage [18:40] minimal: i was talking about things like `preserve_hostname: false` in the final example on the page, `preserve_hostname` is not a base config key, but a module config one. so this hints that modules configs can also be part of those files [18:41] as is "disable_root" [18:42] but to turn your previous reasoning back on you, the docs do not say setting arbitrary module configs there is supported ;-) [18:42] yes, but the doc doesn't state explicitely that modules configs can be part of those files, so... can they? or is there just a few special cases accepted? or is the example wrong? or... [18:43] minimal: exactly, which is why i ask if this behavior is actually accurate [18:44] no idea [18:49] depends on whether the docs are written from a "common law" (what is not forbidden is permitted) or "civil law" (what is permitted is defined, everything else is forbidden) perspective ;-) [18:53] well to be honest, i always found that cloud-init doc lacks a lot of info... i've always ended up reading the sources to understand how it works. but that's quite a "hacky" way to go, which is why i'm here now, hoping some cloud-init guru can tell how it _should_ be done [18:54] eventually if i decide to actually use cloud-init for my project, i'll create some issues about all that [18:55] but at this point... seems to me that simply creating an init script and forget about cloud-init would be way easier and reliable [18:59] you mentioned you're running on DO so I assume you'll still need cloud-init in the OS image for DO-related config [19:01] i am on DO yes, but the idea is not to be tied to it, but provide a generic image made with packer that would behave the same on other cloud providers [19:01] right, my point is that typically "cloud providers" means having cloud-init in the OS image [19:02] well cloud-init being in the image doesn't mean i _have_ to use it [19:02] or that i have to find convoluted ways to integrate with it [19:03] i.e. an init script that run at the right time can still query cloud-init metadata and act according to it [19:03] correct, I was just clarifying whether you meant removing cloud-init from the OS image [19:04] na, any cloud provider will rely on it, it has to stay [19:08] which DataSource are you using for DO BTW? [19:09] actually that init script would make things quite easy. i'm just investigating if there is a way to make my code part of the cloud-init process, with the idea of having any cloud related task in the same place [19:10] minimal: i haven't checked that yet, i also discovered that the DigitalOcean datasource is considered deprecated XD [19:11] yes, I was the one who brought up the issue that DO themselves didn't seen to be using the DO datasource and used ConfigDrive instead, which lead to the deprecation [19:12] it seems a lot of cloud providers use ConfigDrive [19:14] I wouldn't say that myself, it tends to be used mainly for OpenStack deployments === domovoy__ is now known as domovoy