Symptoms:
By having a VM that has cloud-init installed within it, it is possible to automate the set/reset process by using Openstack
Resolution:
Procedure:
1) Create or modify a "cloud-init.cfg" file to be used in desired VMs with the following content (in this example to change the password):
#cloud-config
chpasswd:
list: |
root:<NEW_PASSWORD>
expire: False
2) Encoding it by using base64:
# base64 cloud-init.cfg
3) Once you have the base64-encoded string, you should use it as per the following Openstack command to apply it (could be using string or file path):
To create a new VM with a certain password:
# openstack --insecure server create --image <IMAGE_ID> --flavor <FLAVOR_ID> --user-data '<BASE64_ENCODED_STRING>' <INSTANCE_NAME>
or
# openstack --insecure server create --image <IMAGE_ID> --flavor <FLAVOR_ID> --user-data <USER_DATA_FILE> <INSTANCE_NAME>
For an existing VM:
# openstack --insecure server set --config-drive true --user-data '<BASE64_ENCODED_STRING>' <INSTANCE_NAME_OR_ID>
or
# openstack --insecure server set --config-drive true --user-data <USER_DATA_FILE> <INSTANCE_NAME_OR_ID>
* Remember that you could review all the complete options directly on the cloudinit page:
https://cloudinit.readthedocs.io/en/latest/tutorial/qemu.html#what-is-user-data
https://cloudinit.readthedocs.io/en/latest/tutorial/qemu.html#define-our-user-data
Optionally, If you have chosen to boot from a template or volume, which has cloud-init and OpenSSH installed:
Related Ticket(s):
#406253