Howto execute one global script when VM creation/boot in OpenStack

I need to execute one global script when VM creation/boot in OpenStack.
Example:
openstack server create myserver ...
Then that the OpenStack instance execute one script that is the same for all this OpenStack instance.

I do not mean to use "--user-data", because this is for apply one custom (and local) script.

How do I do this?

One example of this is the following:

I have one OpenStack enviroment. With many tenants, many VM by tenant, multiple projects.

Then, for all VMs for this OpenStack enviuronment, when I create/boot one other VM (from one image without personalizations, without sensible information), then always need do the same tasks, example:
curl -o /path/generalcert.cert http://myprivateurl/generalcert.cer
echo "Welcome private banner" > /etc/motd
etc.....

For to do these tasks:
- I can use --user-data "myprovisionscript.sh". But, all people working in the same OpenStack environment, need to use same script, and known it, and maintain for all.
- I need (configuring of any form the OpenStack Server), that this common script run transparently for all users when any user create/boot any instance, without specify --user-data, only using "openstack server create myserver ...". In this way, that these common tasks are maintained by the OpenStack administrator.

I read a bit that exist "meta-data", "vendor-data", etc. I do not know if it is possible to use this to add a script that always runs when create/boot one VM.

4 answers

Hi, reading the possibilities:
I can use one metadata propoerty in a image (using openstack image set --property myproperty=value), and when I create a VM from this image, that the VM can read this property?

OpenStack doesn’t interfere with the software that runs on the VM. You can set meta data, which is one or more key-value pairs, on an instance. You can provide an SSH key to the instance, or a user data script. All these things, however, don’t change the software that runs on the instance or the data on the instance.

Rather, the instance must process this information. For example, SSH keys and user data are usually processed with cloud-init. Even though you can “inject” files, this term is misleading, and in reality the instance pulls those files; they are not forcibly added to the instance from outside.

In short, if each instance needs to do the same thing, you need to either build some custom code into the image, or provide data to cloud-init (which is included in practically all cloud images). Which brings us back to user-data.

I suppose your problem would be solved if you could define default user-data, which would be added to an instance even without the —user-data option. AFAIK this is not possible.